Lecture 12
Lecture 12
In many applications where linear systems appear, one needs to solve Ax = b for many dierent vectors b. For instance, a structure must be tested under several dierent loads, not just one. As in the example of a truss (9.2), the loading in such a problem is usually represented by the vector b. Gaussian elimination with pivoting is the most ecient and accurate way to solve a linear system. Most of the work in this method is spent on the matrix A itself. If we need to solve several dierent systems with the same A, and A is big, then we would like to avoid repeating the steps of Gaussian elimination on A for every dierent b. This can be accomplished by the LU decomposition, which in eect records the steps of Gaussian elimination.
LU decomposition
The main idea of the LU decomposition is to record the steps used in Gaussian elimination on A in the places where the zero is produced. Consider the matrix: 1 2 3 A = 2 5 12 . 0 2 10 The rst step of Gaussian elimination is to subtract 2 times the rst row from the second row. In order to record what we have done, we will put the multiplier, 2, into the place it was used to make a zero, i.e. the second row, rst column. In order to make it clear that it is a record of the step and not an element of A, we will put it in parentheses. This leads to: 1 2 3 (2) 1 6 . 0 2 10 There is already a zero in the lower left corner, so we dont need to eliminate anything there. We record this fact with a (0). To eliminate the third row, second column, we need to subtract 2 times the second row from the third row. Recording the 2 in the spot it was used we have: 1 2 3 (2) 1 6 . (0) (2) 2 Let U be the upper triangular matrix produced, and let L be the lower triangular matrix with the records and ones on the diagonal, i.e.: 1 2 3 1 0 0 U = 0 1 6 , L = 2 1 0 , 0 0 2 0 2 1
43
44
3 12 = A. 10
Thus we see that A is actually the product of L and U . Here L is lower triangular and U is upper triangular. When a matrix can be written as a product of simpler matrices, we call that a decomposition of A and this one we call the LU decomposition.
45
Exercises
12.1 Solve the systems below by hand using the LU decomposition. Pivot if appropriate. In each of the two problems, check by hand that LU = P A and Ax = b. (a) A = (b) A = 2 .5 4 4 , , b= b= 0 3 3 2
1 4 3 5
12.2 Finish the following Matlab function program: function [x1, e1, x2, e2] = mysolve(A,b) % Solves linear systems using the LU decomposition with pivoting % and also with the built-in solve function A\b. % Inputs: A -- the matrix % b -- the right-hand vector % Outputs: x1 -- the solution using the LU method % e1 -- the norm of the residual using the LU method % x2 -- the solution using the built-in method % e2 -- the norm of the residual using the built-in method format long Test the program on both random matrices (randn(n,n)) and Hilbert matrices (hilb(n)) with n large (as big as you can make it and the program still run) and document the results.