520 NUMERICAL SOLUTION OF SYSTEMS OF LINEAR EQUATIONS
smallest index i
:2::
k that yields
c"
in (8.2.12), and if i
=I=
k, then interchange
rows
i and k. Also interchange
s~"l
and
s~kl,
and denote the resulting
new
values
by
s~k+
1
l,
j =
1,
...
, n, most of which have not changed.
Then
proceed
with the elimination algorithm of
Section 8.1,
as
before. This form of scaling
seems to be the form most commonly used in current published algorithms, if
scaling
is
being used.
An
algorithm for Gaussian elimination
We
first
give
an algorithm, called Factor,
for the triangular factorization of a matrix
A.
It uses Gaussian elimination with
·partial pivoting, combined with the implicit scaling of (8.2.10) and (8.2.12).
We
then give a second algorithm, called Solve, for using the results of Factor to solve
a linear system
Ax
=
b.
The reason for separating the elimination procedure into
these two steps
is
that
we
will often want to solve several systems
Ax
= b, with
the same
A,
but different values for
b.
Algorithm Factor (A, n, Pivot, det, ier)
1 Remarks:
A is an n X x matrix, to be factored using the
LU
decomposition. Gaussian elimination
is
used, with partial pivot-
ing and implicit
scaling in the rows. Upon completion of the
algorithm, the upper triangular matrix
U will be stored in the
upper triangular part of
A;
and the multipliers of (8.1.1), which
make up
L below its diagonal, will be stored in the correspond-
ing positions of
A.
The vector Pivot will contain a record of all
row interchanges.
If
Pivot (
k)
= k, then no interchange was used
in step
k of the elimination process. But if Pivot (
k)
= i
=1=
k,
then rows
i and k were interchanged in step k of the elimination
process. The variable det will contain
det-(A)
on
exit.
The variable ier
is
an error indicator.
If
ier =
0,
then the
routine
was
completed satisfactorily. But for ier = 1, the matrix
A
was
singular, in the sense that all possible pivot elements were
zero at some step
o{
the elimination process.
In
this case, all
computation
ceased, and the routine was exited.
No
attempt is
made to check
on
the accuracy of the computed decomposition
of
A, and it can be nearly singular without being detected.
2 det
:=
1
3
s
1
:=
Max
jaiil'
i = 1,
...
,
n.
l:Sj:Sn
4 Do through step
16
for k = 1,
...
, n - 1.
5
c"
:=
Max I
atk
I
k:Si:Sn
S
1
6 Let i
0
be
the smallest index i
:2::
k for which the maximum in
step
5
is
attained. Pivot (
k)
:=
i
0
•
7
If
c"
=
0,
then ier
:=
1, det
:=
0, and exit from the algorithm.