Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
15 views

Lecture 12

The document discusses LU decomposition, which is a method for solving systems of linear equations Ax = b efficiently when the same matrix A is used for multiple right-hand sides b. LU decomposition factors a matrix A into the product of a lower triangular matrix L and an upper triangular matrix U. This decomposition is recorded by placing the elimination coefficients in L. Then solving systems Ax = b involves first pivoting b, then solving two triangular systems Ly = b and Ux = y using back substitution. LU decomposition avoids re-factorizing A each time and instead just performs back substitution.

Uploaded by

Dulal Manna
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views

Lecture 12

The document discusses LU decomposition, which is a method for solving systems of linear equations Ax = b efficiently when the same matrix A is used for multiple right-hand sides b. LU decomposition factors a matrix A into the product of a lower triangular matrix L and an upper triangular matrix U. This decomposition is recorded by placing the elimination coefficients in L. Then solving systems Ax = b involves first pivoting b, then solving two triangular systems Ly = b and Ux = y using back substitution. LU decomposition avoids re-factorizing A each time and instead just performs back substitution.

Uploaded by

Dulal Manna
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Lecture 12 LU Decomposition

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

LECTURE 12. LU DECOMPOSITION

then we have the following mysterious coincidence: 1 2 1 0 0 1 2 3 LU = 2 1 0 0 1 6 = 2 5 0 2 0 2 1 0 0 2

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.

Using LU to solve equations


If we also include pivoting, then an LU decomposition for A consists of three matrices P , L and U such that: P A = LU. (12.1) The pivot matrix P is the identity matrix, with the same rows switched as the rows of A are switched in the pivoting. For instance: 1 0 0 P = 0 0 1 , 0 1 0 would be the pivot matrix if the second and third rows of A are switched by pivoting. Matlab will produce an LU decomposition with pivoting for a matrix A with the following command: > [L U P] = lu(A) where P is the pivot matrix. To use this information to solve Ax = b we rst pivot both sides by multiplying by the pivot matrix: P Ax = P b d. Substituting LU for P A we get: LU x = d. Then we need only to solve two back substitution problems: Ly = d and U x = y. In Matlab this would work as follows: > A = rand(5,5) > [L U P] = lu(A) > b = rand(5,1) > d = P*b > y = L\d > x = U\y > rnorm = norm(A*x - b) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Check the result. We can then solve for any other b without redoing the LU step. Repeat the sequence for a new right hand side: c = randn(5,1); you can start at the third line. While this may not seem like a big savings, it would be if A were a large matrix from an actual application.

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.

You might also like