Let L be a lower-triangular matrix (n×n) and U be an upper-triangular matrix (also n×n).
We've discussed how to solve Ux=y with backward substitution:
xi=yi−n∑j=i+1uijxjuii,i=n,n−1,…,2,1.We also discussed how to solve Ly=b with forward substitution:
yi=bi−i−1∑j=1lijyjlii,i=1,2,…,n−1,n.Assume that we can express A as LU and we want to solve Ax=b:
Ax=LUx=b=L(Ux)=b.Recall from Lecture 9 that backward substitution requires O(n2) operations. The same is true of forward substitution.
To solve Ax=b when a factorization A=LU is known therefore also requires O(n2) operations.
This should be compared with Gaussian elimination with backward substitution (or worse, matrix inversion), which requires O(n3) operations.
But what if the LU factorization is not known in advance? How much effort is required to compute it? The answer is O(n3) because Gaussian elimination is the means by which we LU-factorize, as we will see next.
Thus LU factorization and Gaussian elimination are just two sides of the same coin.
Assume A is an n×n matrix that can be put in upper-triangular form without row swaps (we'll deal with those next lecture).
Consider the 3×3 case first
A=[a11a12a13a21a22a23a31a32a33]Here a(1)22=a22−a12a21a11 and a(1)23=a23−a13a21a11. The question that will lead us to an LU factorization is: What type of matrix does this row operation correspond to?
Recall that the goal is to express A=LU, so we find the inverse of the lower-triangular matrix:
[100a21/a1110001][100−a21/a1110001]=[100010001]So, after a single step, we have found
[a11a12a13a21a22a23a31a32a33]=[100a21/a1110001][a11a12a130a(1)22a(1)23a31a32a33]This is closer to a lower/upper factorization.
Next we perform the row operation R3−a31a11R1→R3 which corresponds to
[100010−a31/a1101][a11a12a130a(1)22a(1)23a31a32a33]=[a11a12a130a(1)22a(1)230a(1)32a(1)33]where a(1)32=a32−a12a31a11 and a(1)33=a33−a13a31a11
The inverse of the lower-triangular factor can be confirmed
[100010a31/a1101][100010−a31/a1101]=[100010001]Thus:
[a11a12a130a(1)22a(1)23a31a32a33]=[100010a31/a1101][a11a12a130a(1)22a(1)230a(1)32a(1)33]Combine the two row operations to yield:
[a11a12a13a21a22a23a31a32a33]=[100a21/a1110001][100010a31/a1101][a11a12a130a(1)22a(1)230a(1)32a(1)33]which can be written as:
[a11a12a13a21a22a23a31a32a33]=[100a21/a1110a31/a1101][a11a12a130a(1)22a(1)230a(1)32a(1)33]This brings us very close to an LU factorization
For the last step, we need to perform R3−a(1)32a(1)22R2→R3
[1000100−a(1)32/a(1)221][a11a12a130a(1)22a(1)230a(1)32a(1)33]=[a11a12a130a(1)22a(1)2300a(2)33]where a(2)33=a(1)33−a(1)23a(1)32a(1)22.
Again, you can check that the inverse of the matrix on the left is simple
[1000100a(1)32/a(1)221][1000100−a(1)32/a(1)221]=[100010001]so that we get:
[a11a12a130a(1)22a(1)230a(1)32a(1)33]=[1000100a(1)32/a(1)221][a11a12a130a(1)22a(1)2300a(2)33]Inserting this into the existing factorization:
[a11a12a13a21a22a23a31a32a33]=[100a21/a1110a31/a1101][a11a12a130a(1)22a(1)230a(1)32a(1)33]yields:
[a11a12a13a21a22a23a31a32a33]=[100a21/a1110a31/a1101][1000100a(1)32/a(1)221][a11a12a130a(1)22a(1)2300a(2)33]The inner factors simplify and we have an LU factorization
[a11a12a13a21a22a23a31a32a33]=[100a21/a1110a31/a11a(1)32/a(1)221][a11a12a130a(1)22a(1)2300a(2)33]The LU algorithm (no row interchanges)
INPUT a n x n matrix A
OUTPUT the LU factorization of A, or a message of failure
STEP 1: Set L to be the n x n identity matrix;
STEP 2: For j = 1, 2, ...,n do STEPS 3-4
STEP 3: If A(j,j) = 0
OUTPUT('LU Factorization failed')
STOP.
STEP 4: For i = j+1, j+2, ... , n do STEPS 5-6
STEP 5: Set L(i,j) = A(i,j)/A(j,j);
STEP 6: Perform row operation Ri - L(i,j)*Rj --> Ri on A;
STEP 7: OUTPUT([L,A]);