Docsity

Numerical Linear Algebra, Lecture Notes - Mathematics - 4, Study notes of Mathematical Methods for Numerical Analysis and Optimization

Toggle sidebar
bg1
9 Standard Gaussian Elimination
Probably the best known method for solving a square system Ax=bis Gaussian elimi-
nation. It represents, as well as the QR method, a direct way of solving such systems.
The aim of Gaussian elimination is also to reduce a linear system of equations Ax=bto
an upper triangular system, Ux=cby applying very simple linear transformations to it,
which do not change the solution.
Suppose we have a linear system of the form
a11x1+a12x2+... +a1nxn=b1
a21x1+a22x2+... +a2nxn=b2
.
.
..
.
.
an1x1+an2x2+...+ann xn=bn,
then, assuming that a11 != 0, we can multiply the first row by a21
a11 and subtract the resulting
row from the second row, which cancels the factor in front of x1in that row. Then, we
can multiply the original first row by a31
a11 and subtract it from the third row, which, again,
cancels the factor in front of x1in that row.
Continuing like this all the way down, we end up with an equivalent linear system of the
form
a11x1+a12x2+... +a1nxn=b1
a(2)
22 x2+...+a(2)
2nxn=b(2)
2
.
.
..
.
.
a(2)
n2x2+...+a(2)
nnxn=b(2)
n.
Assuming now that a(2)
22 != 0, we can repeat the whole process using the second row now to
eliminate x2from row three to n, and so on. Hence, after k−1, k≥2, steps the system
can be written in matrix form as
A(k)x=
a11 ∗∗ ... ∗
0a(2)
22 ∗... ∗
...
00 a(k)
kk ... a
(k)
kn
.
.
..
.
..
.
..
.
.
00 a(k)
nk ... a
(k)
nn
x=
b(1)
1
b(2)
2
.
.
.
b(k)
k
.
.
.
b(3)
n
,(8)
24
pf3
pf4
pf5
pf8
pf9

Partial preview of the text

Download Numerical Linear Algebra, Lecture Notes - Mathematics - 4 and more Study notes Mathematical Methods for Numerical Analysis and Optimization in PDF only on Docsity!

9 Standard Gaussian Elimination

Probably the best known method for solving a square system Ax = b is Gaussian elimi-

nation. It represents, as well as the QR method, a direct way of solving such systems.

The aim of Gaussian elimination is also to reduce a linear system of equations Ax = b to

an upper triangular system, U x = c by applying very simple linear transformations to it,

which do not change the solution.

Suppose we have a linear system of the form

a 11

x 1

  • a 12

x 2

+... + a 1 n

x n

= b 1

a 21

x 1

  • a 22

x 2

+... + a 2 n

x n

= b 2

a n 1

x 1

  • a n 2

x 2

+... + a nn

x n

= b n

then, assuming that a 11

= 0, we can multiply the first row by

a 21

a 11

and subtract the resulting

row from the second row, which cancels the factor in front of x 1 in that row. Then, we

can multiply the original first row by

a 31

a 11

and subtract it from the third row, which, again,

cancels the factor in front of x 1 in that row.

Continuing like this all the way down, we end up with an equivalent linear system of the

form

a 11

x 1

  • a 12

x 2

+... + a 1 n

x n

= b 1

a

(2)

22

x 2 +... + a

(2)

2 n

xn = b

(2)

2

a

(2)

n 2

x 2 +... + a

(2)

nn xn =^ b

(2)

n.

Assuming now that a

(2)

22

= 0, we can repeat the whole process using the second row now to

eliminate x 2

from row three to n, and so on. Hence, after k − 1, k ≥ 2, steps the system

can be written in matrix form as

A

(k)

x =

a 11 ∗ ∗... ∗

0 a

(2)

22

0 0 a

(k)

kk

... a

(k)

kn

0 0 a

(k)

nk

... a

(k)

nn

x =

b

(1)

1

b

(2)

2

b

(k)

k

b

(3)

n

If in each step a

(k)

kk

is different from zero, Gaussian elimination produces an upper triangular

matrix.

For theoretical (not numerical) reasons, it is useful to rewrite this process using matrices.

Definition 9.1 For 1 ≤ i ≤ n, let x ∈ R

n such that ej x = 0 for j ≤ i, that is

x = (0, 0 ,... , 0 , x i+

,... , x n

T .

An elementary lower triangular matrix is given by

L

i

(x) := I − xe

T

i

0 0... −xi+1 1... 0

0 0... −xn 0... 1

Remark 9.2 An elementary lower triangular matrix has the following properties:

(a) det Li(x) = 1,

(b) L i

(x)

− 1 = L i

(−x),

(c) multiplying a matrix A with Li(x) from the left leaves the first i rows unchanged and,

starting from row i + 1, subtracts the row vector x j

(a i 1

,... , a in

) from row j of A.

9.1 The LU -decomposition

Naturally, Gaussian elimination is not realised by matrix multiplication, but by program-

ming the corresponding operations directly. This leads to an O(n

3 ) complexity. In addition,

we have an O(n

2 ) complexity for solving the final linear system by back substitution.

However, there is another way of looking at the process.

Suppose we may construct a sequence of n − 1 elementary lower triangular matrices Lj =

L

j

(m j

) such that

Ln− 1 Ln− 2 · · · L 2 L 1 A = U

is an upper triangular matrix.

Since L i

(m i

− 1 = L i

(−m i

) (exercise), we have

A = L 1 (−m 1 )L 2 (−m 2 ) · · · Ln− 2 (−mn− 2 )Ln− 1 (−mn− 1 )U

= (I + m 1 e

T

1

)(I + m 2 e

T

2

) · · · (I + mn− 2 e

T

n− 2

)(I + mn− 1 e

T

n− 1

)U

= (I + m n− 1

e

T

n− 1

  • m n− 2

e

T

n− 2

  • · · · + m 2

e

T

2

  • m 1

e

T

1

)U

=: LU,

where L is lower triangular with unit diagonal elements.

Rearranging these equations, and using the fact that !ii = 1 for all 1 ≤ i ≤ n, we find that

ij

u jj

a ij

j− 1 ∑

k=

ik

u kj

, 2 ≤ i ≤ n, 1 ≤ j ≤ i − 1 , (9)

u ij

= a ij

i− 1 ∑

k=

ik

u kj

, 1 ≤ i ≤ n, i ≤ j ≤ n. (10)

Thus, the elements of U in the first row are u 1 j = a 1 j , 1 ≤ j ≤ n and the elements of L in

the first column are! 11

= 1 and! i 1

= a i 1

/u 11

, 2 ≤ i ≤ n.

The equations (9) and (10) can now be used for the calculation of the elements !ij and uij.

For each value of i, starting with i = 2, we calculate first! ij

for 1 ≤ j ≤ i − 1 in order,

and then the values of u ij

for i ≤ j ≤ n, again in increasing order. We then move on to

the same calculation for i + 1 and so on until i = n.

The complexity of this procedure is O(n

3 ).

Remark 9.7 If A = LU then the linear system Ax = b = LU x can be solved in two steps.

First, we solve Ly = b by forward substitution and then U x = y by back substitution. Both

is possible in O(n

2 ) time.

9.2 Pivoting

Consider the matrix

A =

This matrix is non-singular and is well-conditioned, κ(A) = (3+

5)/2, in the 2-norm. But

Gauss elimination fails at the first step, since a 11

= 0. Note that, a simple interchanging

of the rows will give an upper triangular matrix. Furthermore, a simple interchanging

of columns leads to a lower triangular matrix. The first corresponds to rearranging the

equations in the linear system, the latter corresponds to rearranging the unknowns.

Furthermore, consider the slightly perturbed matrix

A =

− 20 1

Using Gauss elimination on this matrix, gives the factors

L =

20 1

, U =

− 20 1

20

However, if we are using floating point arithmetic with machine precision ≈ 10

− 16

. The

number 1 − 10

20 will not be represented exactly, but by its nearest floating point, let us

say that this is the number − 10

20

. Using this number produces the factorisation

L =

20 1

U =

− 20 1

20

The matrix

U is relatively close to the correct U with respect to ‖U ‖. But on calculating

the product we obtain

L

U =

− 20 1

We see that this matrix is not close to A, since a 1 has been replaced by a 0. Suppose we

wish to solve Ax = b with b = (1, 0)

T using floating point arithmetic we would obtain

x^ ˜ = (0, 1)

T while the true answer is approximately (− 1 , 1)

T

. The explanation for this is

that LU factorisation is not backward stable.

The exchange of rows or columns during the Gaussian elimination process is referred to as

Pivoting. Assume we have performed k − 1 steps and now have a matrix of the form

A

(k)

=

a 11

0 a

(2)

22

0 0 a

(k)

kk

... a

(k)

kn

0 0 a

(k)

nk

... a

(k)

nn

Now, if det A = det A

(k) ! = 0, not all the entries in the column vector (a

(k)

kk

,... a

(k)

nk

T can

be zero. Hence, we can pick one entry and swap the corresponding row with the kth row.

This is usually referred to as partial (row) pivoting. For numerical reasons it is reasonable

to pick a row! with

|a !k

| = max

k≤i≤n

|a

(k)

ik

In a similar way, partial column pivoting can be defined. Finally, we could use total pivoting,

i.e. we could pick indices !, m ∈ {k, k + 1,... n} such that

|a!m| = max

k≤i,j≤n

|a

(k)

ij

Usually, partial row pivoting is implemented.

To understand the process of pivoting in an abstract form, it is useful to introduce permu-

tation matrices.

Definition 9.8 An n × n elementary permutation matrix is any matrix of the form

P

ij

= I − (e i

− e j

)(e i

− e j

T .

That is P ij

is an identity matrix with rows i and j (columns) interchanged. A permutation

matrix is the (finite) product of elementary permutations matrices.

function [U,L,P] = par_piv_gauss(A)

n = size(A,1);

U = A;

L = eye(n);

P = eye(n);

for i = 1:n-

u = U(i,:);

l = L(i,1:i-1);

p = P(i,:);

r = find(max(abs(U(i:n,i))));

r =r+i-1;

U(i,:) = U(r,:);

U(r,:) = u;

L(i,1:i-1) = L(r,1:i-1);

L(r,1:i-1) = l;

P(i,:) = P(r,:);

P(r,:) = p;

for j = i+1:n

L(j,i) = U(j,i)/U(i,i);

U(j,i:n) = U(j,i:n) - L(j,i)*U(i,i:n);

end

end

P = P’;

9.3 Cholesky Factorisation

Let us assume that A has an LU factorisation A = LU and that A is symmetric, i.e.

A

T = A. Then we have

LU = A = A

T

= U

T

L

T

.

Since U

T is a lower triangular matrix and L

T is an upper triangular matrix, we would

like to use the uniqueness of the LU factorisation to conclude that L = U

T and U = L

T .

Unfortunately, this is not possible since the uniqueness requires the lower triangular matrix

to be normalised, i.e. to have only ones as diagonal entries, and this may not be the case

for U

T .

But if A is invertible, we can write

U = D

U

with a diagonal matrix D = diag(d 11

,... , d nn

) and a normalised upper triangular matrix

U. Then, we can conclude that A = LD

U and hence A

T

U

T DL

T = LD

U , so that

we can now apply the uniqueness result to derive L =

U

T and U = DL

T , which gives

A = LDL

T

.

Let us finally make the assumption that all diagonal entries of D are positive. Then, we

can define the square root of D by setting D

1 / 2 = diag(

d 11

d nn

), which leads to

the decomposition

A = (LD

1 / 2

)(LD

1 / 2

)

T

=

L

L

T

.

Definition 9.12 A decomposition of a matrix A of the form A = LL

T with a lower trian-

gular matrix L is called a Cholesky factorisation of A.

It remains to verify for what kind of matrices a Cholesky factorisation exists.

Theorem 9.13 Suppose A = A

T is positive definite. Then, A possesses a Cholesky fac-

torisation.

Proof: A matrix A is positive definite if and only if the determinant of every upper

principal sub-matrix Ap is positive. From Theorem 9.4 we can therefore conclude that A =

LU is possible. Since a positive definite matrix is also invertible, our previous derivation

shows that A = LDL

T

. Finally, A being positive definite also means that

d ii

= e

T

i

De i

= e

T

i

(L

− 1 AL

−T )e i

= (L

−T e i

T A(L

−T e i

where we use the short notation L

−T for (L

− 1 )

T

.!

For the numerical algorithm, it is again useful to write A = LL

T component-wise taking

into account that L is lower triangular. For i ≥ j we have

aij =

j ∑

k=

!ik!jk =

j− 1 ∑

k=

!ik!jk + !ij !jj.

This can first be resolved for i = j:

jj

a jj

j− 1 ∑

k=

2

jk

1 / 2

With this, we can successively compute the other coefficients. For i > j we have

ij

!jj

a ij

j− 1 ∑

k=

ik

jk

It can be shown that the computational complexity is approximately n

3 /6 + O(n

2 ), which

is about half the complexity of the standard Gauss elimination process. However, here, we

also have to take n roots.