Skip to content

LU factorisation

Keep the multipliers of elimination and a matrix splits into two triangles, so each new right-hand side costs two quick sweeps, not a new elimination.

Helps to know firstThe inverse matrix

Helps to know first
This topic

First, the picture

Elimination throws its multipliers away. Keep them, and the matrix splits into two triangles. Watch each one drop into place.

Elimination, written down

Each multiplier of elimination drops into its cell of L.

A, and an empty L with ones on its diagonal, ready to keep the multipliers.

0.00 / 13.40 s
Describe this picture

Two grids of cells side by side: the matrix A\mathbf{A}, and a lower triangle labelled L\mathbf{L} with ones on its diagonal, zeros above it and empty places below. As elimination clears each entry below a pivot, the row changes, and its multiplier appears as a highlighted cell beside the row, then slides into the matching place of L\mathbf{L}: 3 into row 2, column 1; 0 into row 3, column 1; 2 into row 3, column 2. When the first grid has become upper triangular it is relabelled U\mathbf{U}. A third grid then fills cell by cell, row by row, with the product LU\mathbf{L}\mathbf{U}, and when it is full its label reads LU=A\mathbf{L}\mathbf{U}=\mathbf{A}: the same numbers as the matrix at the start. The picture has no control.

Keep the multipliers

On the page Elimination we turned

A=[121381041]intoU=[12102−2005]\mathbf{A}=\begin{bmatrix}1&2&1\\3&8&1\\0&4&1\end{bmatrix} \quad\text{into}\quad \mathbf{U}=\begin{bmatrix}1&2&1\\0&2&-2\\0&0&5\end{bmatrix}

with the multipliers ℓ21=3\ell_{21}=3, ℓ31=0\ell_{31}=0 and ℓ32=2\ell_{32}=2. Now put those multipliers in a lower triangle, below a diagonal of ones:

L=[100310021].\mathbf{L}=\begin{bmatrix}1&0&0\\3&1&0\\0&2&1\end{bmatrix}.

Then A=LU\mathbf{A}=\mathbf{L}\mathbf{U}. This is the LU factorisation: L\mathbf{L} is lower triangular, U\mathbf{U} is upper triangular, and their product is A\mathbf{A}.

Why does it work? Elimination made each row of U\mathbf{U} by taking multiples of earlier rows away from a row of A\mathbf{A}. Run that backwards, and each row of A\mathbf{A} is its row of U\mathbf{U} plus those same multiples put back. Row 2 of A\mathbf{A} is 3 times row 1 of U\mathbf{U} plus row 2 of U\mathbf{U}:

3 (1,2,1)+(0,2,−2)=(3,8,1).3\,(1,2,1)+(0,2,-2)=(3,8,1).

Row 3 of A\mathbf{A} is 0 times row 1 plus 2 times row 2 plus row 3 of U\mathbf{U}: 2 (0,2,−2)+(0,0,5)=(0,4,1)2\,(0,2,-2)+(0,0,5)=(0,4,1). Each row of L\mathbf{L} lists how much of each row of U\mathbf{U} to add, and that is what the product LU\mathbf{L}\mathbf{U} does.

So LU is not a new method. It is elimination, written down.

Watch the signs. On the elimination page, the step matrix E21\mathbf{E}_{21} held −3-3, because the step takes 3 of row 1 away. In L\mathbf{L} the 3 appears with a plus sign, because rebuilding puts it back. In matrices, L\mathbf{L} undoes the steps in reverse order, as the page The inverse matrix said an undo must:

L=E21−1 E31−1 E32−1.\mathbf{L}=\mathbf{E}_{21}^{-1}\,\mathbf{E}_{31}^{-1}\,\mathbf{E}_{32}^{-1}.

Solving with two triangles

Now solve Ax=b\mathbf{A}\mathbf{x}=\mathbf{b}, which is L(Ux)=b\mathbf{L}(\mathbf{U}\mathbf{x})=\mathbf{b}. Give the inside a name, c=Ux\mathbf{c}=\mathbf{U}\mathbf{x}, and split the job in two:

Lc=b,thenUx=c.\mathbf{L}\mathbf{c}=\mathbf{b},\qquad\text{then}\qquad \mathbf{U}\mathbf{x}=\mathbf{c}.

Both are triangles, so both are quick. Take b=(2,12,2)\mathbf{b}=(2,12,2), the right-hand side from the elimination page. Lc=b\mathbf{L}\mathbf{c}=\mathbf{b} is solved from the top down, a forward substitution:

c1=2,c2=12−3⋅2=6,c3=2−0⋅2−2⋅6=−10.c_1=2,\qquad c_2=12-3\cdot2=6,\qquad c_3=2-0\cdot2-2\cdot6=-10.

These are the right-hand sides that elimination produced, 2, 6 and −10-10. Then Ux=c\mathbf{U}\mathbf{x}=\mathbf{c} is solved from the bottom up, by back substitution: 5z=−105z=-10 gives z=−2z=-2; 2y−2z=62y-2z=6 gives 2y+4=62y+4=6, so y=1y=1; and x+2y+z=2x+2y+z=2 gives x+2−2=2x+2-2=2, so x=2x=2.

Many right-hand sides

The work is in the factoring. Once L\mathbf{L} and U\mathbf{U} are known, a new b\mathbf{b} needs only the two sweeps.

One factoring, many solves

Lc = b from the top, then Ux = c from the bottom.

The factors L and U, kept from one elimination.

0.00 / 16.80 s
Describe this picture

Two lines of cells, one above the other. The top reads L\mathbf{L}, then a column c\mathbf{c}, an equals sign and a column b\mathbf{b}; the bottom reads U\mathbf{U}, a column x\mathbf{x}, an equals sign and a copy of c\mathbf{c}. The factors stay on screen while two right-hand sides pass through them one after the other. Each first fills c\mathbf{c} from the top, the row of L\mathbf{L} in use lit up, then c\mathbf{c} is copied down and x\mathbf{x} fills from the bottom, row by row of U\mathbf{U}. The first, b=(2,12,2)\mathbf{b}=(2,12,2), gives c=(2,6,−10)\mathbf{c}=(2,6,-10) and x=(2,1,−2)\mathbf{x}=(2,1,-2); the second, b=(4,12,5)\mathbf{b}=(4,12,5), gives c=(4,0,5)\mathbf{c}=(4,0,5) and x=(1,1,1)\mathbf{x}=(1,1,1). The picture has no control.

Try the second one yourself before the picture finishes: b=(4,12,5)\mathbf{b}=(4,12,5). Forward: c1=4c_1=4, c2=12−3⋅4=0c_2=12-3\cdot4=0, c3=5−0−2⋅0=5c_3=5-0-2\cdot0=5. Back: 5z=55z=5, so z=1z=1; 2y−2=02y-2=0, so y=1y=1; x+2+1=4x+2+1=4, so x=1x=1. Check: A (1,1,1)=(4,12,5)\mathbf{A}\,(1,1,1)=(4,12,5).

How much cheaper is it? Factoring an n×nn\times n matrix takes about n3/3n^3/3 multiply-and-subtract steps, as the elimination page counted. Each sweep through a triangle takes about n2/2n^2/2, so a solve takes about n2n^2. For n=1000n=1000, the factoring takes about 3.3×1083.3\times10^8 steps and each later solve about 10610^6: about 330 times less.

Row exchanges

Elimination sometimes needs a row exchange, when a pivot is 0. Take

A=[0231].\mathbf{A}=\begin{bmatrix}0&2\\3&1\end{bmatrix}.

The first pivot is 0. Swap the rows first, with the permutation matrix P=[0110]\mathbf{P}=\begin{bmatrix}0&1\\1&0\end{bmatrix}, which is the identity with its rows swapped. Then PA=[3102]\mathbf{P}\mathbf{A}=\begin{bmatrix}3&1\\0&2\end{bmatrix} is already upper triangular, so U=PA\mathbf{U}=\mathbf{P}\mathbf{A} and L=I\mathbf{L}=\mathbf{I}. In general, with the exchanges done first,

PA=LU.\mathbf{P}\mathbf{A}=\mathbf{L}\mathbf{U}.

Library programs exchange rows more often than this page does. They move the largest available number into each pivot place, because that keeps rounding errors small. SciPy, for example, makes two exchanges on the 3×33\times3 matrix above, even though none of its pivots is 0. Its L\mathbf{L} and U\mathbf{U} then differ from ours, but they solve the same system.

Worked example

  1. Read L\mathbf{L} from the multipliers. Multipliers 33, 00, 22 give ℓ21=3\ell_{21}=3, ℓ31=0\ell_{31}=0, ℓ32=2\ell_{32}=2 in L\mathbf{L}, below a diagonal of ones.
  2. Rebuild A\mathbf{A}. Row 2: 3 (1,2,1)+(0,2,−2)=(3,8,1)3\,(1,2,1)+(0,2,-2)=(3,8,1). Row 3: 2 (0,2,−2)+(0,0,5)=(0,4,1)2\,(0,2,-2)+(0,0,5)=(0,4,1).
  3. First solve. b=(2,12,2)\mathbf{b}=(2,12,2) gives c=(2,6,−10)\mathbf{c}=(2,6,-10) and x=(2,1,−2)\mathbf{x}=(2,1,-2).
  4. Second solve. b=(4,12,5)\mathbf{b}=(4,12,5) gives c=(4,0,5)\mathbf{c}=(4,0,5) and x=(1,1,1)\mathbf{x}=(1,1,1), with no new elimination.
  5. Signs. In E21\mathbf{E}_{21} the entry in row 2, column 1 is −3-3; in L\mathbf{L} it is +3+3.
  6. A zero pivot. [0231]\begin{bmatrix}0&2\\3&1\end{bmatrix} needs P=[0110]\mathbf{P}=\begin{bmatrix}0&1\\1&0\end{bmatrix}; then U=[3102]\mathbf{U}=\begin{bmatrix}3&1\\0&2\end{bmatrix} and L=I\mathbf{L}=\mathbf{I}.

Where you’ll meet this

A circuit simulator stepping through time often solves with the same matrix at every step, with a new right-hand side each time. It factors once and then only sweeps. Programs that compute how a structure bends under many different loads do the same: one factoring, one quick solve per load. In SciPy, a free Python library, the pair of functions lu_factor and lu_solve splits the work exactly this way.

In signal processing · sparse matrix factorisation

The FFT is a factorisation too. The page The FFT writes the full matrix of the discrete Fourier transform as a product of a few matrices that are mostly zeros, after a reordering of the samples. Like L\mathbf{L} and U\mathbf{U}, the factors are much quicker to apply than the matrix they replace.

Reference card

QuantityFormulaNotes
FactorisationA=LU\mathbf{A}=\mathbf{L}\mathbf{U}elimination, written down
L\mathbf{L}multipliers ℓpq\ell_{pq} below a diagonal of oneswith a plus sign
U\mathbf{U}the result of eliminationpivots on its diagonal
StepsL=E21−1E31−1E32−1\mathbf{L}=\mathbf{E}_{21}^{-1}\mathbf{E}_{31}^{-1}\mathbf{E}_{32}^{-1}undo in reverse order
SolveLc=b\mathbf{L}\mathbf{c}=\mathbf{b}, then Ux=c\mathbf{U}\mathbf{x}=\mathbf{c}forward, then back substitution
Row exchangesPA=LU\mathbf{P}\mathbf{A}=\mathbf{L}\mathbf{U}P\mathbf{P} reorders the rows
Costfactor ≈n3/3\approx n^3/3, each solve ≈n2\approx n^2factor once, solve many times

Keep reading with a free account.

By creating an account you accept the terms of use.

Sign in

Already have an account? Use the service you signed up with.

Or keep reading: get new lessons by email

Are you 13 or over?

Accounts and email updates are for people aged 13 or over. We keep only your answer, never your date of birth.

End of the lesson

Where to go next.

Phasorium

Account

Sign inKeep your place on any device

Subjects

Site

Look