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=LU and we want to solve Ax=b:
Ax=LUx=b=L(Ux)=b.Recall from Lecture 9 that backward substitution requires
n2+3n2multiplications, andn2+n2additions.The same is true of forward substitution.
To solve Ax=b when a factorization A=LU is known requires
n2+3nmultiplications, andn2+nadditions.This should be compared with Gaussian elimination with backward substitution (or worse, matrix inversion) that requires ∼n3/3 operations.
Even if you could compute A−1 for free, computing x=A−1b requires (again, see Lecture 9) n2 multiplications and n2−n additions. This is nearly the same number of operations as the LU method.
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]R2−a21a11R1→R1Here 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 on the left-hand side:
[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.
If 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]We use this with our expression from the first step
[a11a12a130a(1)22a(1)23a31a32a33]=[100010a31/a1101][a11a12a130a(1)22a(1)230a(1)32a(1)33][a11a12a13a21a22a23a31a32a33]=[100a21/a1110001][a11a12a130a(1)22a(1)23a31a32a33]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][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]
[a11a12a13a21a22a23a31a32a33]=[100a21/a1110a31/a1101][1000100a(1)32/a(1)221][a11a12a130a(1)22a(1)2300a(2)33]This 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]);
function [L,A] = LU(A)
% this function will give two output matrices
end
A = rand(4)
[L,U] = LU(A);
L
U
norm(A-L*U)