LU decomposition
30.3
Introduction In this section we consider another direct method for obtaining the solution of systems of equations in the form AX = B .
① revise
matrices and their use in systems of equations
Prerequisites Before starting this Section you should
. . .
Learning Outcomes After comp After completi leting ng thi thiss Sect Section ion yo you u sho should uld be able to . . .
② revise
determinants
✓ find
an LU decomposition of simple matrices and apply it to solve systems of equations
✓ be
aware of when an LU decomposition is unavailable and when it is possible to circumvent the problem
1. LU decomposition Suppose we have the system of equations AX = B .
The motivation for an LU decomposition is based on the observation that systems of equations involving triangular coefficient matrices are easier to deal with. Indeed, the whole point of Gaussian Elimination is to replace the coefficient matrix with one that is triangular. The LU decomposition is another approach designed to exploit triangular systems. We suppose that we can write A = LU where L is a lower triangular matrix and U is an upper triangular matrix. Our aim is to find L and U and once we have done so we have found an LU decomposition of A.
Key Point An LU decomposition of a matrix A is the product of a lower triangular matrix and an upper triangular matrix that is equal to A.
It turns out that we need only consider lower triangular matrices L that have 1s down the diagonal. Here is an example, let
1 = 3 2 = 0
A
1 where = Multiplying out L
2 4 8 14 6 13
= .
LU
0 0 U 11 U 12 U 13 L21 U 22 U 23 1 0 and U 0 0 U 33 L31 L32 1 LU and setting the answer equal to A gives
U 11 L21 U 11 L31 U 11
U 12 L21 U 12 + U 22 L31 U 12 + L32 U 22
1 = 3
2 4 8 14 2 6 13
U 13 L21 U 13 + U 23 L31 U 13 + L32 U 23 + U 33
.
Now we have to use this to find the entries in L and U . Fortunately this is not nearly as hard as it might at first seem. We begin by running along the top row to see that U 11 = 1 ,
U 12 = 2 ,
U 13 = 4 .
Now consider the second row L21 U 11 = 3
∴
L 21 × 1 = 3
L21 U 12 + U 22 = 8 L21 U 13 + U 23 = 14
∴
∴
L21 = 3 ,
3 × 2 + U 22 = 8
∴
3 × 4 + U 23 = 14
HELM (VERSION 1: March 18, 2004): Workbook Level 1 30.3: Introduction to Numerical Methods
∴
U 22 = 2 , ∴
U 23 = 2 .
2
Notice how, at each step, the equation in hand has only one unknown in it, and other quantities that we have already found. This pattern continues on the last row L31 U 11 = 2
∴
L 31 × 1 = 2
L31 U 12 + L32 U 22 = 6
∴
L31 = 2 ,
∴
2 × 2 + L32 × 2 = 6
L31 U 13 + L32 U 23 + U 33 = 13
∴
∴
L32 = 1 ,
(2 × 4) + (1 × 2) + U 33 = 13
∴
U 33 = 3 .
We have shown that A
1 = 3
2 4 8 14 2 6 13
1 = 3
0 0 1 0 2 1 1
1 0
2 4 2 2 0 0 3
and this is an LU decomposition of A.
Find an LU decomposition of
3 1 . −6 −4
Your solution
− − − − .
2 1
0 3
1 2 0 1
=
− 6 − 4 L n f o n o i t i s o p m o c e d U a s i 1 3
4 1
6 3
e c n e H 2 1 1 2 1 2 U t a U + U L d U L − = 2 2 − = 2 2 − = 1 2 L s − = 1 1 . 2 h t s e i l p m i h c i h w 4 n a 2 e i l p m i h c i h w 6 U , 3 = 1 1 U t a , 1 = 2 1 h t s e i l p m i w o r y b w o r s e d i s d n a h t h g i r d n a t f e l e h t g n i r a p m o c , n e h t
2 1 1 2 1 2 U + U L 1 1 U L = 2 1 1 1 U U 2 2
3
U 0 2 1 U 1 1 U 2 2
− 6 − 1 1 2 L 4 U L = = 0 1 1 3
t e L
HELM (VERSION 1: March 18, 2004): Workbook Level 1 30.3: Introduction to Numerical Methods
3 decomposition of −6
1 6 0 −16 0 8 −17
Find an LU
.
Your solution
L n . x i r t a m n e v i g e h t f o n o i t i s o p m o c e d U a s i
− 0 0 1 − 2 0 4 6 1 3
− 8 0 1 4 0 7 1 − = 6 − 0 6 − 0 1 2 1 0 0 1 6 1 3
t a h t s w o l l o f t i d n a U − = 3 3 1 U − = 3 2 4 3 1 , 6 = U
2 3 L 4 = 2 2 , 2 = U 2 1 , 1 = U
1 3 L 0 = , 2 − = 1 2 L 1 1 , 3 = U
t a h t e e s e w w o r y b w o r s t n e m e l e g n i r a p m o c d n a
3 2 2 3 3 1 1 3 U + U L + U L 3 2 3 1 1 2 U + U L 3 1 U 3 3
2 1 1 3 U L + U L 2 2 2 1 1 2 U + U L 2 1 U 2 2 2 3
− 8 0 U L 7 1 1 1 1 2 U L = 6 − 0 6 − 1 1 1 U 6 1 3 1 1 1 3
t e s e w s e t o n e h t n i e l p m a x e d e k r o w e h t m o r f l a i r e t a m g n i s U
HELM (VERSION 1: March 18, 2004): Workbook Level 1 30.3: Introduction to Numerical Methods
4
2. Using an LU decomposition to solve systems of equations Once a matrix A has been decomposed into lower and upper triangular parts it is possible to obtain the solution to AX = B in a direct way. The procedure can be summarised as follows • Given A, find L and U so that A = LU . Hence LU X = B . • Let Y = U X so that LY = B . Solve this triangular system for Y . • Finally solve the triangular system U X = Y for X . The benefit of this approach is that we only ever need to solve triangular systems. The cost is that we have to solve two of them.
Example Find the solution of X
1 of 3 =
2 4 8 14 2 6 13
x1 x2 x3
3 = 13 x1 x2 x3
.
4
Solution • The first step is to calculate the LU decomposition of the coefficient matrix on the lefthand side. In this case that job has already been done since this is the matrix we considered earlier. We found that L
1 = 3
1 2 4 = 0 2 2 0 0 3 . That is we consider = for the vector = 1 0 0 3 = 13 = = 3 1 0
• The next step is to solve LY
LY
0 0 1 0 2 1 1
,
U
B
.
Y
2 1 1
y1 y2 y3
y1 y2 y3
B
4
which can be solved by forward substitution . From the top equation we see that y1 = 3. The middle equation states that 3y1 + y 2 = 13 and hence y2 = 4. Finally the bottom line says that 2y1 + y2 + y3 = 4 from which we see that y3 = −6.
5
HELM (VERSION 1: March 18, 2004): Workbook Level 1 30.3: Introduction to Numerical Methods
Solution (contd.) • Now that we have found Y we finish we solve 1 2 U X = 0 2 0 0
the procedure by solving U X = Y for X . That is 4 2 3
3 = 4 = x1 x2 x3
Y
−6
by using back substitution . Starting with the bottom equation we see that 3x3 = −6 so clearly x3 = −2. The middle equation implies that 2x2 + 2x3 = 4 and it follows that x2 = 4. The top equation states that x1 + 2 x2 + 4 x3 = 3 and consequently x1 = 3. Therefore we have found that the solution to the system of simultaneous equations
1 3
2 4 8 14 2 6 13
3 = 13 x1 x2 x3
Use the LU decomposition 3 1 6 x1 x2 = −6 0 −16 0 8 −17 x3
4
is
X
3 = 4
.
−2
0you found earlier in this Section to solve 4 . 17
Your solution
HELM (VERSION 1: March 18, 2004): Workbook Level 1 30.3: Introduction to Numerical Methods
6
− −
− 1 1 X x t a . 0 = s i n o i t u l o s d e r i u q e r e h T . 2 = h t s u s e v i g e n i l p o t 2 − = 3 x t a h e h t n e h t d n a , 0 = 2 x t a h t s w o h s n e h t e n i l e l d d i m e h T . 1 t s w o h s e n i l m o t t o b e h T 1 . 4 = 0
x 2 x 1 x 3
1 4 6
0 0 2 0 1 3
e v a h e w , X r o f 3 3 2 2 Y = X U y e r o y + y y e v l o s e w y l l a n i F . 1 = f e r e h t d n a 7 1 = 4 t a h t s u s l l e t e n i l t s a l e h T . 4 = 1 − t a y e r o f e r e h t d n a 4 = 2 y + 2 h t s e t a t s e n i l e l d d i m e h T . 0 = 1 y t a h t s e i l p m i e n i l p o t e h T
3 y 7 1 . 4 = 2 y 1 y 0
− 0 0 1 . 4 − 2 0 6 1 3
7
1 4 0 − 0 1 2 0 0 1
Y L e e v a h e w , Y r o f B = v l o s e w t s r i F
1 4 0 L o t l a u q e s i x i r t a m t n e i c ffi e o c e h t t a h t r e i l r a e d n u o f e W − = U 0 1 2 0 0 1
HELM (VERSION 1: March 18, 2004): Workbook Level 1 30.3: Introduction to Numerical Methods
3. Do matrices always have an LU decomposition? No. Sometimes it is impossible to write a matrix in the form “lower triangular” × “upper triangular”.
Why not? An invertible matrix A has an LU decomposition provided that all its leading submatrices have non-zero determinants. The k -th leading submatrix of A is denoted Ak and is the k × k matrix found by looking only at the top k rows and leftmost k columns. For example if
1 = 3
1 2
1 = 3
A
2 4 8 14 2 6 13
then the leading submatrices are A1 = 1,
A2 =
3 8
,
A3
2 4 8 14 2 6 13
.
The fact that this matrix A has an LU decomposition can be guaranteed in advance because none of these determinants is zero: |A1 | = 1, |A2 | = (1 × 8) − (2 × 3) = 2, 8 14 3 14 3 8 |A3 | = − 2 +4 6 13 2 13 2 6
= 20 − (2 × 11) + (4 × 2) = 6
(where the 3 × 3 determinant was found by expanding along the top row).
1 Example Show that 2
2 3 4 5 1 3 4
does not have an
LU decomposition.
Solution The second leading submatrix has determinant equal to
1 2
2 4
= (1 × 4) − (2 × 2) = 0
which means that an LU decomposition is not possible in this case.
HELM (VERSION 1: March 18, 2004): Workbook Level 1 30.3: Introduction to Numerical Methods
8
Which, if any, of these matrices have an LU decomposition? 1 −3 7 3 2 0 1 (i) A = , (ii) A = , (iii) A = −2 6 1 0 1 3 2 0 3 −2
.
Your solution (i)
L n | = | 2 A | d | . n o i t i s o p m o c e d U a e v a h s e o d A o s , o r e z s i e s e h t f o r e h t i e N . 3 = | A n a 3 = | 1 A
Your solution (ii)
L n | . n o i t i s o p m o c e d U a e v a h t o n s e o d A o s 0 = | 1 A
Your solution (iii)
L n | , 1 = | 1 A | . n o i t i s o p m o c e d U a e v a h t o n s e o d A o s , 0 = 6 − 6 = | 2 A
The example below gives some strong evidence for the key result being stated in this section.
Can we get around this problem? Yes. It is always possible to re-order the rows of an invertible matrix so that all of the submatrices have non-zero determinants.
Example Reorder the rows of A decomposition.
9
1 = 2
2 3 4 5 1 3 4
so that the reordered matrix has an
LU
HELM (VERSION 1: March 18, 2004): Workbook Level 1 30.3: Introduction to Numerical Methods
Solution Swapping the first and second rows doesn’t help us since the second leading submatrix will still have a zero determinant. Let us swap the second and third rows and consider B
1 = 1
2 3 3 4 2 4 5
the leading submatrices are B1 = 1,
B2 =
1 2 1 3
,
B3 = B .
Now |B1 | = 1, |B2 | = 3 × 1 − 2 × 1 = 1 and (expanding along the first row) |B3 | = 1(15 − 16) − 2(5 − 8) + 3(4 − 6) = −1 + 6 − 6 = −1. All three of these determinants are non-zero and we conclude that B does indeed have an LU decomposition.
Reorder the rows of A an LU decomposition.
1 = −2
−3 7 6 1 0 3 −2
so that the reordered matrix has
Your solution
HELM (VERSION 1: March 18, 2004): Workbook Level 1 30.3: Introduction to Numerical Methods
10
L n . n o i t i s o p m o c e d U a e v a h d e e d n i s e o d B t a h t e d u l c n o c e w d n a o r e z - n o n e r a e s e h t f o l l A . y l e v i t c e p s e r 5 4 d n a 3 , 1 s t n a n i m r e t e d e v a h h c i h w
3 B = B ,
3 0 2 1 B , 1 = B = − 1 3 e r a s e c i r t a m b u s g n i d a e l e h t
− 1 6 2 B − 3 0 = 2 − 1 7 3 r e d i s n o c d n a s w o r d r i h t d n a d n o c e s e h t p a w s s u t e L
11
HELM (VERSION 1: March 18, 2004): Workbook Level 1 30.3: Introduction to Numerical Methods
Exercises 1. Calculate LU decompositions for each of these matrices (a) A (b) A
(c) A
2 1 = −42 1 −6−4 = 2 1 −2 6 3 −11 1 3 2 = 2 8 5 1 11 4
2. Check each answer in Question 1, by multiplying out LU to show that the product is equal to A. 3. Using the answers obtained in Question 1, solve the following systems of equations.
2 1 1 (a) = −4 −6 2 2 1 −4 15 = 7 (b) 2 1 −2 41 61 33 −11 2 2 = 3 (c) 2 8 5 1 11 4 0 1 6 2 5 4. Consider = 2 12 x1 x2
x1 x2 x3
x1 x2 x3
A
−1 −3 −1
(a) Show that A does not have an LU decomposition. (b) Re-order the rows of A and find an LU decomposition of the new matrix. (c) Hence solve x1 + 6x2 + 2x3 = 9
2x1 + 12x2 + 5x3 = −4 −x1 − 3x2 − x3 = 17
HELM (VERSION 1: March 18, 2004): Workbook Level 1 30.3: Introduction to Numerical Methods
12