Page 87 - Compact Numerical Methods For Computers
P. 87
76 Compact numerical methods for computers
Algorithm 5. Gauss elimination with partial pivoting (cont.)
begin {STEP 2a}
s := abs(A[j,j]); k := j;
for h := (j+l) to n do {STEP 2b}
begin
if abs(A[h,j])>s then
begin
s := abs(A[h,j]); k := h;
end;
end; {loop on h}
if k<>j then {STEP 3 -- perform row interchange. Here we do this
explicitly and trade time for the space to store indices
and the more complicated program code.}
begin
writeln(‘Interchanging rows ’,k,‘ and ’,j);
for i := j to (n+p) do
begin
s := A[k,i]; A[k,i] := A[j,i]; A[j,i] := s;
end; {loop on i}
det := det; {to change sign on determinant because of interchange}
end; (interchange)
det := det*A[j,j]; {STEP 4}
if abs(A[j,j])<tol then
begin
writeln(‘Matrix computationally singular -- pivot < ’,tol);
halt;
end;
for k := (j+l) to n do {STEPS}
begin
A[k,j] := A[k,j]/A[j,j]; {to form multiplier m[k,j]}
for i := (j+1) to (n+p) do
A[k,i] := A[k,i]-A[k,j]*A[j,i]; {main elimination step}
end; {loop on k -- STEP 6}
det := det*A[n,n]; {STEP 7}
if abs(A[n,n])<tol then
begin
writeln(‘Matrix computationally singular -- pivot < ’,tol);
halt;
end;
end, {loop on j -- this ends the elimination steps}
writeln(‘Gauss elimination complete -- determinant = ’,det);
end; {alg05.pas}
The array A now contains the information
m = A[i, j] for i > j
ij
R = A[i, j] for i < j < n
ij
(j)
f = A[i,j] for j = n+1, n+2, . . . , n+p
i
that is, the elements of the p right-hand sides.