Lecture 18 · Week 5· 17:48

LU factorisation

Elimination as a factorisation, solving with LU.

Play: Lecture 18: LU factorisation
Lecture · 17:48 · Open on YouTube · Report a problem with this video
TranscriptThe full text of the lecture. Click any sentence to play the video from there.

Today: elimination, recorded

Welcome back. Last time, we saw that every row operation is a multiplication by a matrix: doing the operation to A is the same as multiplying A on the left by an elementary matrix E. Today we put that to work. In practice, we often solve many systems with the same matrix A, but with different right hand sides: the same bridge under different loads, or the same circuit with different inputs. Each time, elimination performs the same row operations on A, and only the right hand side changes. So it makes sense to do the work on A once, and to keep a record of it.

That record is the L U factorisation. We write A as L times U. Here U is the echelon form that elimination produces, and L stores the multipliers that were used to get there. Today we see how elimination becomes a factorisation, and why the multipliers land exactly in L. Then we solve systems with L and U, count how much work this saves, and see what to do when a row swap is needed.

Elimination as a product of matrices

Here is our example. A has first row (two, one, one), second row (four, five, three), and third row (minus two, eight, four). The first pivot is the two in the top left corner. To clear the four below it, we divide it by the pivot: four divided by two is two. This number is called the multiplier. Then we replace row two by row two minus two times row one.

Column by column: four minus two times two is zero, five minus two times one is three, and three minus two times one is one. This step is a multiplication by E one: the identity matrix, with minus two in row two, column one. Next, the minus two in row three. The multiplier is minus two divided by two, which is minus one. So we replace row three by row three minus minus one times row one, which means adding row one.

Minus two plus two is zero, eight plus one is nine, and four plus one is five. This step is E two: the identity, with a one in row three, column one. The second pivot is the three. Below it is a nine, so the multiplier is nine divided by three, which is three. We replace row three by row three minus three times row two.

Zero minus three times zero is zero, nine minus three times three is zero, and five minus three times one is two. This step is E three: the identity, with minus three in row three, column two. Now the matrix is in echelon form, with pivots two, three, and two. We call it U. So, in the language of matrices, E three times E two times E one times A equals U. And the three multipliers were two, minus one, and three.

From the steps to L

To get A back, we undo the three steps, in reverse order. Each elementary matrix is invertible, and its inverse is the reverse row operation: to undo subtracting a multiple of a row, we add it back. So A equals E one inverse, times E two inverse, times E three inverse, times U. Each inverse just flips the sign of the multiplier entry: plus two, minus one, and plus three. Let's multiply these three inverses, starting from the right. E two inverse times E three inverse performs the operation of E two inverse on E three inverse: row three minus row one. So row three becomes (minus one, three, one).

Then E one inverse adds two times row one to row two. Row one is (one, zero, zero), so row two becomes (two, one, zero). The result has ones on the diagonal and zeros above it. Below the diagonal sit exactly the multipliers: two, minus one, and three, each in the position of the entry it cleared. This matrix is L. Compare the product in the other order, E three E two E one, which performs the elimination. E two E one has first row (one, zero, zero), second row (minus two, one, zero), and third row (one, zero, one).

Then E three subtracts three times row two from row three. In the first entry, one minus three times minus two is seven. A seven appears that is not one of our multipliers. Undoing the steps in reverse order is what keeps the multipliers apart. Here is the definition. A square matrix is unit lower triangular if it is lower triangular, and every entry on its diagonal is one. An L U factorisation of an m by n matrix A is a product A equals L U, where L is an m by m unit lower triangular matrix, and U is an m by n matrix in echelon form. Let's check that L times U is A. By the row-column rule, row i of L U is a combination of the rows of U, with the entries of row i of L as the weights.

Row one of L is (one, zero, zero), so row one of L U is just row one of U, the row (two, one, one). Row two of L is (two, one, zero). So row two of L U is two times the row (two, one, one), plus the row (zero, three, one). In the first entry, that is four. In the second, two plus three is five. In the third, two plus one is three. Row three of L is (minus one, three, one). So row three of L U is minus the row (two, one, one), plus three times the row (zero, three, one), plus the row (zero, zero, two). In the first entry, that is minus two. In the second, minus one plus nine is eight. In the third, minus one plus three plus two is four. Together with rows one and two, this is A.

Why the multipliers land in L

This is no accident. Here is the theorem. Let A be an m by n matrix over a field F. Suppose the forward phase of elimination brings A to an echelon form U using only replacements, with no row swaps. In stage p, row p is the pivot row, and each lower row i is replaced by row i minus l i p times row p. Put each multiplier l i p into row i, column p of a unit lower triangular matrix L, with zero wherever no step was needed. Then A equals L U. The proof is short, but it needs care, so take it slowly, and pause or rewatch it if you need to.

First, look at row p at the moment it becomes the pivot row. From then on, it never changes again: later steps only change the rows below it. So at that moment, row p is already row p of U. So every step subtracts a multiple of a row of U. Row i is changed only in the stages one up to i minus one. So in the end, row i of U is row i of A, minus l i one times row one of U, and so on, down to minus l i, i minus one, times row i minus one of U. Now move the subtracted rows to the other side. Row i of A is l i one times row one of U, plus and so on, up to l i, i minus one, times row i minus one of U, plus one times row i of U.

And that is exactly row i of L U. By the row-column rule, it is a combination of the rows of U, with weights from row i of L: the multipliers l i one up to l i, i minus one, then the one on the diagonal, and then zeros. So every row of A equals the same row of L U, and A equals L U. So to find L, we never multiply matrices. We simply write down each multiplier, in the position of the entry it cleared. Watch it once more on our example.

Solving with L and U

Now we put the factorisation to use. Suppose A equals L U, and we want to solve A x equals b. Then A x is L times U x. So we give U x a name, y, and split the problem in two. First, we solve L y equals b, from the top down. This is called forward substitution. Then we solve U x equals y, from the bottom up, by back substitution. Why does this work? Row one of L y equals b gives y one directly, since the diagonal entry is one. Row two then gives y two, and so on. So L y equals b has exactly one solution.

If x solves U x equals y, then A x is L U x, which is L y, which is b. Conversely, if A x equals b, then U x is a solution of L y equals b, and that solution is unique, so U x equals y. Let's solve A x equals the vector (three, five, minus two), with our L and U. Forward substitution. Row one says y one equals three. Row two says two y one plus y two equals five, so y two is five minus six, which is minus one.

Row three says minus y one, plus three y two, plus y three equals minus two. So y three is minus two, plus three, plus three, which is four. Back substitution, with y equal to (three, minus one, four). Row three of U says two x three equals four, so x three is two. Row two says three x two plus x three equals minus one. So three x two is minus three, and x two is minus one.

Row one says two x one, plus x two, plus x three equals three. So two x one is three plus one minus two, which is two, and x one is one. So x is the vector (one, minus one, two). It is the one solution of our system. As a check, we multiply A by x with the row rule. Row one: two, minus one, plus two, is three. Row two: four, minus five, plus six, is five. Row three: minus two, minus eight, plus eight, is minus two. That is b.

For a new right hand side, we repeat only the two substitutions. The elimination is never done again. And L and U are useful beyond solving systems. In lecture thirty five, we will see that when a square matrix A equals L U, its determinant is the product of the diagonal entries of U.

How much work it saves

How much work does this save? We count multiplications and divisions, for an n by n matrix whose elimination needs no swaps. In stage p of elimination, n minus p rows lie below the pivot row. For each of them, we find the multiplier with one division, and update the n minus p entries to the right of the pivot column, with one multiplication each. So stage p takes at most n minus p rows, times n minus p plus one operations each. For our three by three example, that is six in stage one and two in stage two, eight in all.

Adding over all stages, with k equal to n minus p, the total is at most the sum of k times k plus one, for k from one to n minus one. This works out to n cubed minus n, over three. For n equal to three, that is eight again. For large n, it is about one third of n cubed. The substitutions are much cheaper. In forward substitution, row i needs i minus one multiplications, and no division, since the diagonal entries of L are one. In back substitution, where the diagonal entries of U are the pivots, row i needs n minus i multiplications and one division. Added up, the two take exactly n squared operations. For a thousand unknowns, elimination costs about three hundred and thirty three million operations. Each new right hand side then costs only one million. That is why computers factor a matrix once, and reuse L and U for every new b.

When a row swap is needed

Not every matrix has an L U factorisation. Take the matrix with first row (zero, one), and second row (one, one). Its first pivot position holds a zero, so elimination must start with a swap. In fact, no factorisation exists. Suppose, for a contradiction, that this matrix is L times U. Row one of L U is just row one of U, so row one of U is (zero, one). Row one of U starts in column two. So in an echelon form, row two of U must be all zeros.

Now look at row two, column one of L U. It is the multiplier in L times the zero in the corner of U, plus one times the zero below it. So this entry is zero. But in our matrix it is one. So our assumption was false, and there is no L U factorisation. The fix is to make the swaps first. A permutation matrix is the identity matrix with its rows in some order. Multiplying A on the left by a permutation matrix P puts the rows of A in that same order. And P is invertible: its inverse is its transpose. Here is the theorem. Every m by n matrix A over a field has a factorisation P A equals L U, where P is an m by m permutation matrix, L is unit lower triangular, and U is in echelon form.

The full proof is in the book. The idea is simple: if we knew in advance which swaps elimination will make, we could make them all at the start, and then eliminate with no swaps at all. Here is an example. A has first row (one, two, one), second row (two, four, three), and third row (one, three, two). Row two minus two times row one: two minus two is zero, four minus four is zero, and three minus two is one. Row three minus row one: one minus one is zero, three minus two is one, and two minus one is one.

Now the second pivot position, in row two, column two, holds a zero, and the entry below it is a one. So elimination would have to swap rows two and three. So we make that swap first. P is the identity with rows two and three swapped, and P A has first row (one, two, one), second row (one, three, two), and third row (two, four, three). Eliminating P A needs no swap. Row two minus row one is (zero, one, one). Row three minus two times row one is (zero, zero, one). That is already in echelon form, so the last multiplier is zero.

So L holds the multipliers one, two, and zero below its diagonal, and U is the echelon form we just found. In practice, we do not eliminate twice. We find the swaps during the one pass, and keep a record as we go. Look at our first pass again. Stage one stored the multipliers two, for row two, and one, for row three. Then the zero pivot made us swap rows two and three.

So the stored multipliers swap along with their rows: now row two holds one, and row three holds two. And P is the identity with the same swap. These are exactly the multipliers in L. So a single pass gives P, L and U, with P A equals L U, just as if we had made the swap first. To solve A x equals b, we multiply both sides on the left by P. This gives L U x equals P b. So we swap the entries of b in the same way, and then substitute as before.

Summary

Let's summarise. Elimination without swaps is a factorisation: A equals L U, where U is the echelon form, and L is unit lower triangular. The multipliers go straight into L, each in the position of the entry it cleared. To solve A x equals b, we solve L y equals b by forward substitution, and then U x equals y by back substitution.

Elimination costs about n cubed over three operations, but each new right hand side costs only n squared. When swaps are needed, we make them first, and get P A equals L U. Before the next lecture, read section three point seven of the course book, try the problems on sheet five about L U factorisation, and do the lecture check on this lecture's page at Open Semester dot com. Next time, we meet subspaces: sets of vectors that are closed under addition and scaling, starting with the column space and the null space of a matrix. See you there.

Check yourself

3 questions, from warm-up to stretch

Work each one out on paper, type your answer and press Check. Stuck? Open a hint; the worked solution is there when you need it.

  1. Question 1 of 3 Warm-up

    Let . Find the LU factorisation with and .

    Hint 1 of 2

    Eliminate below the first pivot . The multiplier is the entry to clear divided by the pivot, and it goes into in the position of that entry (Theorem 3.7.4).

    Hint 2 of 2

    . Now do : row becomes .

    Worked solution
    1. The first pivot is . To clear the below it, the multiplier is .
    2. : . So , in row echelon form, and .
    3. The multiplier goes into where it cleared the entry: (Theorem 3.7.4).
    4. Check by the row rule: row of is , row of . Row of is row of , . So .
  2. Question 2 of 3 Core

    with and . Solve for : first by forward substitution, then by back substitution.

    Hint 1 of 2

    Forward substitution goes from the top down: row of gives , then row gives , then row gives . Back substitution goes from the bottom up (Theorem 3.7.5).

    Hint 2 of 2

    Row : . Row : . Row : .

    Worked solution
    1. Forward substitution in : row gives . Row : , so . Row : , so . So .
    2. Back substitution in : row gives , so . Row : , so . Row : , so .
    3. So , the one solution (Theorem 3.7.5).
    4. Check: , and . So .
  3. Question 3 of 3 Stretch

    Let . Does itself have an LU factorisation? Then let , which swaps rows and , and find : give the entries and of and the entry of .

    possible?
    Hint 1 of 2

    Suppose . Row of is row of , so row of would be . What does a row echelon form then say about the first column of , and what is entry of ?

    Hint 2 of 2

    has rows , , . Eliminate with no swaps: , ; after , the multiplier is the new entry in row , column , divided by the pivot .

    Worked solution
    1. No LU factorisation for : suppose, for a contradiction, that . Row of is row of , so row of is . In a row echelon form the rows below it start further right, so the first column of is zero. Then entry of is , but entry of is . So the assumption was false.
    2. puts the rows of in the order : .
    3. Stage : the entry below the pivot in row is already , so . , and gives .
    4. Stage : the pivot is , so , and gives . So .
    5. So and , and (Theorem 3.7.11). Check row by the row rule: .

Found a mistake, or something not working on this page? Report it and we'll fix it. See what we've corrected.