Chapter 3
Chapter 3
Chapter 3
Mathematical Preliminaries
In this chapter we consider the issue of computing the solution of a system of n linear
equations in n unknowns. The scalar form of that system is as follows:
Ax = b,
A=
... ... ... ... ...
an1 an2 ... ... ann
x1
b1
x2
b2
x=
... , b = ... .
xn
bn
We assume the basic property of linear algebra for systems of linear equations like (1).
Proposition 1 The following statements are equivalent:
1. System (1) has a unique solution.
2. det(A) 6= 0.
3. A is invertible.
In this chapter, our objective is to present the basic ideas of a linear system solver. It
consists of two main procedures allowing to solve efficiently (1).
1. The first, referred to as Gauss elimination (or reduction) reduces (1) into an
equivalent system of linear equations, which matrix is upper triangular, specifically
one shows in section 4 that
Ax = b U x = c,
where c Rn and U Rn,n is given by:
...
...
...
...
...
U =
0
0 ... un1,n1 un1,n
0
0 ...
0
unn
1
Thus, uij = 0, i > j. Consequently, one observes that A is invertible if and only if
ni=1 uii = u11 u22 ...unn 6= 0, i.e. uii 6= 0, i.
2. The second consists in solving by back substitution the upper triangular system
(2)
U x = c.
A picture that describes the two steps of the linear solver is the following.
b1
b2
...
bn
We generally assume that the matrix A is a full matrix, that is most of its elements are
non-zero. Storing the augmented matrix AG for a full matrix in its standard form, would
then require N = n (n + 1) words of computer memory. If one uses single precision, 4N
bytes would be necessary, while using double precision would necessitate 8N bytes for that
storage.
Example 1 When the matrix size is n = 2k , the computer memory, for double precision
computation, should exceed N = 8 2k (2k + 1) O(22k+3) bytes.
The following table illustrates the magnitude of memory requirements.
k
n = 2k
N = n (n + 1)
3
6
8
10
8
64
256
1024
72
4160
65792
1049600
in Megabytes
IEEE single precision IEEE double precision
2.7 104
5.5 104
1.6 102
3.2 102
0.25
0.5
4
8
2
UG =
... ... ... ... ... ...
0 ... ... 0 unn cn
Since by default, the lower part of the matrix U consists of zeros, this part of the storage
shall not be waisted but used for other purposes, particularly that of storing the multiplying
factors, which are essential parameters to carry out Gauss elimination procedure. Hence,
at this stage we may consider the data structure U G whether stored by rows or by columns
as consisting of the elements of U and c and unused storage space:
u11
u12 ...
...
u1n c1
unused u22 ...
...
u2n c2
UG =
...
... ...
...
... ...
unused
...
...
unused
unn cn
Although this procedure comes after the completion of the Gauss Reduction step, we shall
deal with it from the start. It indeed provides the importance of this global approach.
Considering (2) in its scalar form, with all diagonal elements uii 6= 0, gives:
u11 u12
0 u22
... ...
0
0
0
0
...
...
u1n
...
...
u2n
...
...
...
... un1,n1 un1,n
...
0
unn
x1
x2
...
xn1
xn
c1
c2
...
=
cn1
cn
Solving (2) by the back substitution procedure reduces such procedure to solving n equations, each one in one unknown only. Starting with the last equation yields xn , then moving
backwards, substituting xn by its computed value - in appropriate rows or columns - yields
xn1 . We reiterate this procedure until the first equation is reached, and where x1 is computed.
We give two versions of the back-substitution process: the first one is column oriented,
while the second one is row oriented. We then evaluate the computational complexity of
each version. Both forms require the same number of flops.
u11 u12
0 u22
... ...
0
0
...
...
...
...
... u1,n1
x1
x2
... u2,n1
...
...
...
0 un1,n1
xn1
c1 u1n xn
c2 u2n xn
...
cn1 un1,n xn
n=length(c) ;
for j=n:-1:1
x(j)=c(j)/U(j,j);
% In all rows above (1(j-1)) replace x(j) by its computed value, shift
the x(j)- terms to the right hand side. Calculate the new right hand side.
for i=1:j-1
c(i)=c(i)- U(i,j) * x(j) ;
end
end
The number of flops needed to execute this algorithm is calculated as follows:
For every j = 1 to n: 1 Division is needed to compute x(j); therefore, a total of n
flops.
For every j = 1 to n, and for every i = 1 to (j 1), to compute the new right hand
side : 1 Addition + 1 Multiplication are used, i.e. a total of:
j1
n X
X
2=
j=1 i=1
n
X
j=1
n.
5
Gauss Reduction
Our starting point is to assume ideal mathematical conditions allowing to carry the reduction without any safeguard. Before setting formally these assumptions, we work out the
following example:
Example 2 Consider the reduction into an upper triangular form of the system:
6x1
2x2 +2x3 +4x4
= 16
6
12
3
6
2 2 4
16
8 6 10
26
13 9 3 19
4 1 18 34
1. Reduction 1. The pivot equation is the 1st equation (k = 1), the pivot element is
a11 = 6. The aim in this step is to eliminate x1 from equations i, where i = 2, 3,
4, by creating 0 as its coefficient. The respective multipliers for each equation i are
1i
= 2, 12 , 1}. Thus, performing (4) repeatedly:
{ aa11
Equation 2 Equation 2 2 Pivot Equation 1,
1
Pivot Equation 1,
2
Equation 4 Equation 4 (1) Pivot Equation 1,
Equation 3 Equation 3
6 2 2 4
16
0 4 2 2
6
0 12 8 1 27
0 2 3 14 18
In order not to waste the implicitly zero storage locations, we use these locations to
place the multipliers. Hence, at the accomplishment of this reduction, the augmented
matrix takes the form:
6
2 2 4
16
2
4 2 2
6
1/2 12 8 1 27
-1
2 3 14 18
with the understanding that boxed elements are the multipliers used in this 1st
reduction.
2. Reduction 2. Perform repeatedly operation(4) with the second pivot equation
(k = 2), the pivot element being a22 = 4, and i successively 3,4. The multipliers are
2i
= 3, 12 }. Thus, to create 0 as coefficient for x2 :
respectively { aa22
Equation 3 Equation 3 3 Equation 2,
The 2nd
1
Equation 4 Equation 4 ( ) Equation 2,
2
reduction yields the following augmented matrix:
6 2 2 4
16
0 4 2 2
6
0 0 2 5 9 .
0 0 4 13 21
After storing the multipliers of the second reduction, the contents of the augmented
matrix updated data structure are as follows:
6
2 2 4
16
2
4 2 2
6
1/2
.
3
2
5
9
-1
-1/2
4 13 21
6 2 2 4 16
0 4 2 2 6
0 0 2 5 9 .
0 0 0 3 3
With the storage of the multipliers, the updated augmented matrix is then:
6
2
2
4 16
2
4
2
2 6
.
1/2
3
2
5
9
-1
-1/2
3 3
We may now discuss the assumptions leading to the Naive Gauss elimination.
4.1
It is the simplest form of Gaussian elimination. The adjective naive applies because this form
is not usually suitable for automatic computation unless essential modifications are made.
We give first the conditions that allow the procedure to work out.
Definition 1 A square matrix An has the principal minor property, if all its principal
sub-matrices Ai , i = 1, ..., n are invertible.
Ai =
... ... ... ... ...
ai1 ai2 ... ... aii
If a matrix A verifies Definition 1 then b Rn,1 , the following algorithms can be applied on
the augmented matrix [A|b]. The first one assumes that the matrix A is stored column-wise.
% The algorithm is column oriented
% The matrix A is assumed to have the principal minor property
% At reduction k, the kth equation is the pivot equation and A(k,k) is
% the pivot element, and equations 1,..,k remained unchanged
function[c,U]=naiveGauss(A,b)
n=length(b) ;
for k=1:n-1
% Get the pivot element and the multipliers proceeding by columns
piv=A(k,k);
for i=k+1:n
8
A(i,k)=A(i,k)/piv;
end
% Modify the body of matrix A proceeding by columns
for j=k+1:n
for i=k+1:n
A(i,j)=A(i,j)-A(i,k)*A(k,j);
end
end
% Modify the right hand side b
for i=k+1:n
b(i)=b(i)-A(i,k)*b(k);
end
end
% Extract U and c proceeding by columns
c=b;
for j=1:n
for i=1:j
U(i,j)=A(i,j);
end
end
It can be shown in case the matrix A verifies Definition 1, that the pivot element at each
reduction is well located on the main diagonal.
The operations count for this algorithm can be easily verified:
1. To find the multipliers:
n1 X
n
X
1=
k=1 i=k+1
n1
X
n k = 1 + 2 + ... + (n 1) =
k=1
n(n 1)
divisions
2
2=
=2
n1 X
n
X
2(n k) = 2
k=1 j=k+1
n(n1)(2n1)
6
n1
X
k=1
n1
X
n(n 1)
2=2
n k = 2[1 + 2 + ... + (n 1)] = 2
2
k=1 i=k+1
k=1
9
4.2
There are several situations where the application of the above algorithm fails although
the matrix A may verify the principal minor property; for example, if the pivot element is
relatively small, this would lead to large multipliers that worsen the round-off errors.To that
end, consider the following example on a linear system of 2 equations in 2 unknowns:
10
Also, rather than interchanging rows to move the desired element into the pivot position, we
use an indexing array to avoid the data movement. Thus, the order in which the equations
are employed is denoted by the row vector IV called the Index Vector. At first, IV is set to
[1, 2, ..., n], then at each reduction, if there would be a permutation in the rows, it is done
only on IV which acts as a vector of pointers to the memory location of the rows. At each
reduction, IV=[i1 , i2 , ..., in ], where the i0j s are integers from 1 to n, in a possibly different order. This eliminates the time consuming and unnecessary process of moving the coefficients
of equations around in the computer memory.
1. Gaussian Elimination with Partial Pivoting
Partial Pivoting consists in first finding at each reduction k, the maximum absolute
value element in column k starting from row k to row n.
- At reduction k = 1 , seek i1 in the set {1, 2, ..., n} such that:
|ai1 ,1 | = max |ai1 | = max {|a11 |, |a21 |, ..., |an1 |}
1in
then perform a permutation of row 1 and row i1 in IV only. Row i1 is the first
Pivot Equation, and ai1,1 is the Pivot Element. We write IV ([1, i1 ]) = IV ([i1 , 1]),
meaning that at this stage,
IV = [i1 , 2, ..., 1..n]
- At reduction k, seek ik in {k, ..., n}, such that:
|aik ,k | = max |aik | = max {|ak,k |, |ak+1,k |, ..., |an,k |}
kin
then perform a permutation of row k and row ik in the last IV. Row ik is
the the Pivot Equation and aik,k is the Pivot element. Therefore, one writes:
IV ([k, ik ]) = IV ([ik , k]).
- At reduction (n-1), seek in1 in {n 1, n}, such that:
|ain1 ,n1 | = max |ai,n1 | = max {|an1,n |, |an,n |}
n1in
12
13
ik=ik+k-1;
IV([k ik])= IV([ik k]) ;
.........Same as Gauss Partial Pivoting..............
3. Example 4
We first set the index vector to IV = [1 2 3 4], and evaluate the scale of the system
IV
1
2
3
4
Augmented matrix
Scales
3 13 9 3 19
13
6 4 1 18 34
18
6 2 2 4
16
6
12 8 6 10
26
12
Augmented
1/2 13 9
-1
4 1
6
2 2
2
8 6
matrix
Scales
3 19
13
18 34
18
4
16
6
10
26
12
Modifying the body of matrix and right hand side leads to:
IV
3
2
1
4
Augmented
1/2 12 8
-1
2 3
6
2 2
2
4 2
15
matrix
Scales
1 27
13
14 18
18
4
16
6
2
6
12
(b) Reduction 2 Similarly to reduction 1, one starts with a search for the pivot
equation:
{
max
IV (2),IV (3),IV (4)
-1
6
2
-1/6
2
1/3
18
6
12
13
2
|; | 312
| =
(c) Reduction 3 This last step keeps the index vector unchanged since max | 318
13
. It is easily verified at the end of the process the contents of the data struc318
ture are as follows.
IV
2
1/2
3
1
4
-1
6
2
Augmented matrix
12
8
1
-1/6
2
1/3
13/3
2
-2/13
27
83/6 45/2
4
16
6/13 6/13
Scales
13
18
6
12
4.3
LU Decomposition
A major by-Product of Gauss Elimination is the decomposition of a matrix into the product
of a unit lower triangular matrix by an upper triangular one. We will base our arguments
on examples 2 and 4.
1. First case : Naive Gauss
Example 2
Going back to example 2, and on the basis of the multipliers of Gauss elimination, let
L and U be respectively the unit lower and upper triangular matrices:
16
1
0
2
1
L=
1
3
2
1 12
Note that the product LU
1
0 0 0
2
1 0 0
1
(6)
3 1 0
2
1 12 2 1
0
0
0
1
0
0
1
2
verifies:
6
0
0
0
2
4
0
0
6 2 2 4
0 4 2 2
U =
0 0 2 5
0 0 0 3
2 4
6 2 2 4
12 8 6 10
2 2
=
2 5 3 13 9 3
0 3
6 4 1 18
which is precisely:
LU = A.
This identity obeys to the following theorem ([2], [3]):
Theorem 1 If a square matrix A Rn,n verifies the principal minor property, then
it can be decomposed into the product of a unit lower triangular matrix L by an upper
triangular matrix U , such that A = LU , where L and U are derived from the Gaussian
elimination process; L is the lower triangular matrix obtained from the multipliers at
each reduction,and U is the final upper triangular matrix of the process.
2. Second case : Gauss Partial Pivoting
Example 4
Consider now the final stage of Gauss reduction in example 4. According to the index
vector IV , we extract successively the upper triangular matrix
6 2
2
4
0 12
8
1
U =
0 0 13/3 83/6
0 0
0
6/13
and the lower unit triangular one,
1
0
0
1/2
1
0
L=
1 1/6
1
2
1/3 2/13
Computation of the product LU
1
0
0
0
1/2
1
0
0
.
1 1/6
1
0
2
1/3 2/13 1
0
0
0
1
gives:
6 2
2
4
6 2 2 4
3 13 9 3
0 12
8
1
=
0 0 13/3 83/6 6 4 1 18
0 0
0
6/13
12 8 6 10
17
e1
e2
I=
...
en
Let IV = [i1 , i2 , ..., in ], where {i1 , i2 , ..., in } a permutation of the integers {1, 2, ..., n}.
The permutation matrix P associated with IV is a permutation of the identity matrix
I, and is given by the row matrix:
ei1
ei2
P (IV ) =
...
ein
In example 4, the index vector final status is IV = [3, 1, 2, 4]. Thus,
e3
0 0 1 0
e1 1 0 0 0
P = P (IV ) =
e2 = 0 1 0 0
e4
0 0 0 1
Note then that the product:
0
1
PA =
0
0
0
0
1
0
1
0
0
0
0
3 13 9 3
0
6 4 1 18
0 6 2 2 4
1
12 8 6 10
is precisely the product LU found above. Hence the general LU decomposition theorem
which generalizes theorem 1 stands as follows.
Theorem 2 Let a square matrix An be processed through partial pivoting Gauss reduction.
If the unit lower triangular matrix L , the upper triangular matrix U and the index vector
IV are extracted from the final status of the process then:
P (IV )A = LU,
18
where P (IV ) is the permutation matrix associated with the last status of the index vector
IV .
Within the scope of this course, the LU decomposition or factorization of A is particularly helpful in computing the determinant of A, in solving different systems of equations
Ax = b, where the coefficient matrix A is held constant, or also in computing the inverse of A,
4.4
Clearly, from theorems 1 and 2, we conclude respectively that in the first case:
det(A) = det(L) det(U )
while in the second case
det(P ) det(A) = det(L) det(U )
where P = P (IV ). Obviously, det(L) = 1, and det(P ) = (1)s , where s is the number of
permutations needed to transform the last IV back to its initial value [1, 2, ..., n].
These results are formulated as follows:
Theorem 3
n
Y
uii ,
i=1
where uii , , i = 1, ..., n are the diagonal elements of the upper triangular matrix U.
(b) Under the hypothesis of Theorem 2,
det(A) = (1)s
n
Y
uii ,
i=1
where s is the number of permutations needed to transform the last index vector IV
obtained, back to its initial status [1, 2, ..., n].
One easily finds in example 2 that:
det(A) = 6 (4) 2 (3) = 144,
and in example 4,
det(P ) det(A) = 6 (12) 13/3 (6/13) = 144
Since s = 2 and det(P ) = 1.
19
4.5
2 1 2
Let A = 2 3 3 be a matrix satisfying the Principal minor property.
6 1 8
The Nave Gauss elimination process leads to the LU
1 0 0
L = 1 1 0 and U =
3 1 1
decomposition of A, where:
2 1 2
0 2 1
0 0 3
1 0 0
y1
2
(a) 1 1 0 y2 = 5
3 1 1
y3
0
By Forward substitution, one obtains: y1 = 2, y2 = 3, y3 = 3
20
2 1 2
x1
2
(b) 0 2 1 x2 = 3
0 0 3
x3
3
By Backward substitution, one obtains: x1 = 1, x2 = 2, x3 = 1.
Changing the right-hand-side, we solve successively:
1 0 0
y1
1
(a) 1 1 0 y2 = 1
3 1 1
y3
3
By Forward substitution, one obtains: y1 = 1, y2 = 0, y3 = 0.
2 1 2
x1
1
0 2 1
x2
0
=
(b)
0 0 3
x3
0
By Backward substitution, one obtains: x1 = 1/2, x2 = 0, x3 = 0.
2. Second case : Gauss Partial Pivoting
Under the hypothesis of Theorem 2, solving Ax = b is equivalent to solving P Ax = P b
or equivalently:
LU x = P b,
Letting P b = c and U x = y, leads to solving successively 2 triangular systems, as in
the preceding situation, i.e. :
Ly = c followed by U x = y.
Example 6
1 1 2
Let A = 2 1 1 .
4 1 2
decomposition of A, where:
1
0
1/2 1
L=
2 2
0
2
1
1
0 1 0
0 ; U = 0 1/2 3/2 ; P = 1 0 0
1
0
0
3
0 0 1
Ly = P b
Ux = y
1
0 0
y1
5
1. 1/2 1 0 y2 = 2
2 2 1
y3
0
By Forward substitution: y1 = 5, y2 = 9/2, y3 = 19
2
1
1
x1
5
2. 0 1/2 3/2 x2 = 9/2
0
0
3
x3
19
By Backward substitution: x1 = 131/6, x2 = 10, x3 = 19/3.
Changing the right-hand-side, we solve successively:
1
0 0
y1
1
1. 1/2 1 0 y2 = 1
2 2 1
y3
3
By Forward substitution: y1 = 1, y2 = 3/2, y3 = 8.
1
2
1
1
x1
2. 0 1/2 3/2 x2 = 3/2
8
0
0
3
x3
4.6
column vectors
of A1 and I.
2 4 2
Let A = 1 3 4 be a given invertible matrix . The Scaled Partial Pivoting Gauss
5 2 0
elimination process leads to the LU decomposition of A, where:
1
0
0
5
2
0
1
0 and U = 0 16/5 2
L = 2/5
1/5 13/16 1
0
0
45/8
The last status of the index vector being IV = [3, 1, 2], the rows of the permutation matrix
P are the row vectors e3 , e1 , e2 and P is then:
0 0 1
P = 1 0 0
0 1 0
with column vectors: e2 , e3 , e1 .
Thus to find A1 one needs to solve successively the following 3-systems of equations:
LU c1 = e2 , LU c2 = e3 , LU c3 = e1
23
1. LU c1 = e2
Letting U c1 = y, we solve successively the 2 triangular systems:
Ly = [0, 1, 0]T
U c1 = y
Forward then Backward substitutions lead to c1 = [4/45, 2/9, 13/90]T
2. LU c2 = e3
Letting U c2 = y, we solve successively the 2 triangular systems:
Ly = [0, 0, 1]T
U c2 = y
Forward then Backward substitutions lead to c2 = [2/45, 1/9, 8/45]T
3. LU c3 = e1
Letting U c3 = y, we solve successively the 2 triangular systems:
Ly = [1, 0, 0]T
U c3 = y
Forward then Backward substitutions lead to c3 = [11/45, 1/9, 1/45]T
The inverse matrix is therefore as follows:
24
PROBLEMS
1. Solve each of the following systems using Naive Gaussian elimination- Carry four significant figures.
x1 + 4x2 x3 = 4
1 1 2 1
x1
1
3 2 1 4 x2 1
(c)
5 8 6 3 x3 = 1
4 2 5 3
x4
1
3x1 + 2x2 x3 = 7
5x1 + 3x2 + 2x3 = 4
(d)
x1 + x2 3x3 = 1
x1 + 3x2 + 2x3 + x4 = 2
x1 + 2x2 + 4x3 + x4 = 1
2. Solve each of the following systems using Gaussian elimination with partial pivoting
and scaled partial pivoting. Carry four significant figures. What are the contents of
the index array at each step?
x1 + 4x2 x3 = 4
1 1 2 1
x1
1
3 2 1 4 x2 1
(c)
5 8 6 3 x3 = 1
4 2 5 3
x4
1
3x1 + 2x2 x3 = 7
5x1 + 3x2 + 2x3 = 4
(d)
x1 + x2 3x3 = 1
25
x1 + 3x2 + 2x3 + x4 = 2
x1 + 2x2 + 4x3 + x4 = 1
3. Using scaled partial pivoting, show how the computer would solve this system of equations. Show the scale array, tell how the pivot rows are selected, and carry out the
computations. Include the index array for each step. You should follow exactly the
scaled-partial-pivoting code, except that you can include the right-hand side of the
system in your calculations , when necessary, as you go along.
4x1 +4x2
+7x4 = 11
(a)
2x1 +x2 +x3 +3x4 = 7
2 3 4 1
1 1 0 2
(b)
3 3
4
3
4 1
0
4
2
1 1 2
x1
(c) 2 1 1 x2 = 2
1
4 1 2
x3
1 0 3 0
0 1 3 1
(d)
3 3 0 6
0 2 4 6
.
4 7
3
2
(e) 1 3
2 4 1
8 1 4 9 2
1
0 3 9 7
(f ) 5 0 1 3 5
4
3 2 2 7
3
0 0 0 9
5x1 + 2x2
=2
26
x1 + x2
3x4 = 4
x1
+ 3x3 + x4 = 0
(h)
x
2 x3 x4 = 3
3x1
+ x3 + 2x4 = 1
4. For each coefficient matrix A of problems 1, 2 and 3, use the LU decomposition of A
to find the determinant oA, and the inverse of A.
27
References
[1] CHENEY, W., KINCAID D., Numerical Mathematics and Computing. 4th edition.
Brooks, Cole 1999.
[2] CIARLET, P., Analyse Numrique Matricielle et Optimisation, Masson, 1985
[3] GOLUB, G.H., VAN LOAN C.F., Matrix Computations. 2nd Edition John Hopkins
University, 1993.
[4] HIGHAM, N., Accuracy and Stability of numerical algorithms. 1996
28