Loading [MathJax]/jax/output/HTML-CSS/jax.js

Matrix factorization

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=yinj=i+1uijxjuii,i=n,n1,,2,1.

We also discussed how to solve Ly=b with forward substitution:

yi=bii1j=1lijyjlii,i=1,2,,n1,n.

Using an LU factorization

Assume that we can express A=LU and we want to solve Ax=b:

Ax=LUx=b=L(Ux)=b.
  1. Solve for y=Ux which is given by Ly=b by forward substitution.
  2. Solve Ux=y for x, because U and y are now known by backward substitution.

Operation count

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 A1 for free, computing x=A1b requires (again, see Lecture 9) n2 multiplications and n2n additions. This is nearly the same number of operations as the LU method.


Having an LU factorization of a matrix is just as good (if not better) as having the inverse matrix

The LU factorization algorithm

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]R2a21a11R1R1
R2a21a11R1R1A=[a11a12a130a(1)22a(1)23a31a32a33]

Here a(1)22=a22a12a21a11 and a(1)23=a23a13a21a11. The question that will lead us to an LU factorization is: What type of matrix does this row operation correspond to?

[100010001][a11a12a13a21a22a23a31a32a33]=[a11a12a13a21a22a23a31a32a33][100a21/a1110001][a11a12a13a21a22a23a31a32a33]=[a11a12a130a(1)22a(1)23a31a32a33]

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][100a21/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 R3a31a11R1R3 which corresponds to

[100010a31/a1101][a11a12a130a(1)22a(1)23a31a32a33]=[a11a12a130a(1)22a(1)230a(1)32a(1)33]

where a(1)32=a32a12a31a11 and a(1)33=a33a13a31a11

The inverse of the lower-triangular factor can be confirmed

[100010a31/a1101][100010a31/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]
[a11a12a13a21a22a23a31a32a33]=[100a21/a1110001][100010a31/a1101][a11a12a130a(1)22a(1)230a(1)32a(1)33][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 R3a(1)32a(1)22R2R3

[1000100a(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)33a(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][1000100a(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]

Example

Compute the LU factorization of

A=[111234111].
In [ ]:
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]);
In [ ]:
function [L,A] = LU(A)
   % this function will give two output matrices
end
In [3]:
A = rand(4)
[L,U] = LU(A);
L
U
norm(A-L*U)
A =

    0.7922    0.8491    0.7431    0.7060
    0.9595    0.9340    0.3922    0.0318
    0.6557    0.6787    0.6555    0.2769
    0.0357    0.7577    0.1712    0.0462


L =

    1.0000         0         0         0
    1.2112    1.0000         0         0
    0.8277    0.2554    1.0000         0
    0.0451   -7.6181  -21.9384    1.0000


U =

    0.7922    0.8491    0.7431    0.7060
   -0.0000   -0.0944   -0.5078   -0.8233
    0.0000         0    0.1701   -0.0972
   -0.0000         0         0   -8.3903


ans =

   2.3420e-15
In [ ]: