Unit 2, lesson 11

LU Factorization and Pivoting

How Gaussian elimination stores its multipliers in a lower triangular L and its result in an upper triangular U, how forward and back-substitution reuse A = LU, and how permutation matrices and partial pivoting give PA = LU.

  • Video 11
  • Inverses and LU Factorization

Two measurements lead to the equations 2x+y=52x + y = 5 and 4x+3y=114x + 3y = 11. Elimination subtracts twice the first equation from the second, which leaves y=1y = 1 and then x=2x = 2. When new measurements arrive, say 11 and 11, only the right side is new, so every elimination step on the coefficients stays the same. This lesson stores the elimination in two triangular matrices so that each new right side costs only two quick substitutions, and it shows how to keep track of row swaps along the way. Tuples such as (5,11)(5, 11) stand for column vectors.

Key terms

Lower and upper triangular matrices

Definition A square n×nn \times n matrix L=[ℓij]L = [\ell_{ij}] is lower triangular if ℓij=0\ell_{ij} = 0 whenever i<ji < j, so every entry above the main diagonal is zero. It is unit lower triangular if, in addition, every diagonal entry equals 11. A square matrix U=[uij]U = [u_{ij}] is upper triangular if uij=0u_{ij} = 0 whenever i>ji > j, so every entry below the main diagonal is zero. A triangular matrix is invertible exactly when all of its diagonal entries are nonzero. A product of lower triangular matrices of the same size is lower triangular, and the same holds for upper triangular and for unit lower triangular matrices.

In plain words A triangular matrix keeps all of its nonzero entries on the diagonal or on one side of it. A system whose coefficient matrix is triangular with nonzero diagonal entries can be solved one unknown at a time.

Example The matrices

L=[1021],U=[2101]L = \begin{bmatrix} 1 & 0 \\ 2 & 1 \end{bmatrix}, \qquad U = \begin{bmatrix} 2 & 1 \\ 0 & 1 \end{bmatrix}

are unit lower triangular and upper triangular. Every echelon form of a square matrix is upper triangular, because the leading entry of row ii lies in column ii or further right.

LU factorization

Definition Let AA be an n×nn \times n matrix, and suppose Gaussian elimination reduces AA to an upper triangular matrix UU without swapping rows. It works through the columns from left to right, and in column jj it applies Ri→Ri−ℓijRjR_i \to R_i - \ell_{ij}R_j to each row i>ji > j. The numbers ℓij\ell_{ij} are the elimination multipliers. Each one is the entry being cleared divided by the pivot in position (j,j)(j, j), so every pivot used as a divisor must be nonzero. Then

A=LU,A = LU,

where LL is the unit lower triangular matrix whose entry in position (i,j)(i, j) below the diagonal is ℓij\ell_{ij}. This is an LU factorization of AA. The reason is that elimination multiplies AA on the left by elementary matrices, giving EA=UEA = U, and L=E−1L = E^{-1} adds back every row multiple that elimination subtracted. That is why the multipliers enter LL with a plus sign.

In plain words Elimination subtracts multiples of higher rows from lower rows. The matrix LL remembers those multiples, and multiplying by LL adds them back, which rebuilds AA from UU.

Example For

A=[2143]A = \begin{bmatrix} 2 & 1 \\ 4 & 3 \end{bmatrix}

the multiplier is ℓ21=4/2=2\ell_{21} = 4/2 = 2, and R2→R2−2R1R_2 \to R_2 - 2R_1 leaves the matrix UU from the previous example. Then

LU=[1021][2101]=[2143]=A.\begin{aligned} LU &= \begin{bmatrix} 1 & 0 \\ 2 & 1 \end{bmatrix} \begin{bmatrix} 2 & 1 \\ 0 & 1 \end{bmatrix} \\[0.4em] &= \begin{bmatrix} 2 & 1 \\ 4 & 3 \end{bmatrix} = A. \end{aligned}

The second row of LULU is twice the first row of UU plus the second row of UU,

2[21]+[01]=[43].2\begin{bmatrix} 2 & 1 \end{bmatrix} + \begin{bmatrix} 0 & 1 \end{bmatrix} = \begin{bmatrix} 4 & 3 \end{bmatrix}.

Storing −2-2 instead, copied from the sign of the row operation, would give the second row [−4−1]\begin{bmatrix} -4 & -1 \end{bmatrix}, which does not rebuild AA.

Forward substitution

Definition Let LL be an n×nn \times n lower triangular matrix with nonzero diagonal entries. Forward substitution solves Lw=bL\mathbf{w} = \mathbf{b} from the top down, computing for i=1,2,…,ni = 1, 2, \dots, n in turn

wi=1ℓii(bi−∑j=1i−1ℓijwj).w_i = \frac{1}{\ell_{ii}}\Bigl(b_i - \sum_{j=1}^{i-1} \ell_{ij} w_j\Bigr).

Each row finds one new unknown from the ones above it, and for a unit lower triangular LL there is no division at all. Back-substitution solves Ux=wU\mathbf{x} = \mathbf{w} for an upper triangular UU with nonzero diagonal entries in the same way from the bottom up. If A=LUA = LU, the system Ax=bA\mathbf{x} = \mathbf{b} reads L(Ux)=bL(U\mathbf{x}) = \mathbf{b}, so it is solved in two triangular steps,

Lw=b,Ux=w.L\mathbf{w} = \mathbf{b}, \qquad U\mathbf{x} = \mathbf{w}.

The back-substitution needs every diagonal entry of UU to be nonzero, which holds exactly when AA is invertible.

In plain words Forward substitution replays the stored elimination on a new right side. Back-substitution then solves the triangular system from the bottom. The vector w\mathbf{w} in the middle is the right side after elimination, not the answer.

Example With LL and UU from above and b=(5,11)\mathbf{b} = (5, 11), forward substitution gives w1=5w_1 = 5 and 2⋅5+w2=112 \cdot 5 + w_2 = 11, so w=(5,1)\mathbf{w} = (5, 1). Back-substitution in 2x+y=52x + y = 5, y=1y = 1 gives y=1y = 1 and x=2x = 2. For the new data b=(1,1)\mathbf{b} = (1, 1) the same factors give w1=1w_1 = 1 and 2+w2=12 + w_2 = 1, so w=(1,−1)\mathbf{w} = (1, -1). Then y=−1y = -1 and 2x−1=12x - 1 = 1, so x=1x = 1. The original equations check, since 2−1=12 - 1 = 1 and 4−3=14 - 3 = 1.

Permutation matrix

Definition An n×nn \times n permutation matrix is a matrix obtained by reordering the rows of InI_n. Each of its rows and each of its columns contains exactly one entry 11, and all other entries are 00. If row ii of PP is row kk of InI_n, then row ii of PAPA is row kk of AA. So multiplying on the left by PP reorders the rows of AA, and PbP\mathbf{b} reorders the entries of b\mathbf{b} in the same way. Every permutation matrix is invertible, with P−1=P⊤P^{-1} = P^{\top}.

In plain words A permutation matrix is the identity with its rows shuffled. Multiplying by it shuffles the rows of whatever comes next in the same way.

Example The matrix

P=[001100010]P = \begin{bmatrix} 0 & 0 & 1 \\ 1 & 0 & 0 \\ 0 & 1 & 0 \end{bmatrix}

consists of rows 3, 1 and 2 of I3I_3. So PAPA lists the rows of AA in the order 3, 1, 2, and P(7,3,20)=(20,7,3)P(7, 3, 20) = (20, 7, 3). Its transpose puts everything back, since P⊤P=I3P^{\top}P = I_3.

Pivoted LU factorization

Definition A pivoted LU factorization of an n×nn \times n matrix AA is

PA=LU,PA = LU,

where PP is an n×nn \times n permutation matrix, LL is unit lower triangular and UU is upper triangular. Every square matrix has one, produced by elimination with row swaps, and PP records the final order of the rows. Since PP is invertible, Ax=bA\mathbf{x} = \mathbf{b} is equivalent to PAx=PbPA\mathbf{x} = P\mathbf{b}, that is, to LUx=PbLU\mathbf{x} = P\mathbf{b}. When AA is invertible, so is UU, and its diagonal entries are nonzero. Then solve Lw=PbL\mathbf{w} = P\mathbf{b} by forward substitution and Ux=wU\mathbf{x} = \mathbf{w} by back-substitution. The permutation reorders the equations, never the unknowns, so x\mathbf{x} needs no reordering at the end.

In plain words When a pivot position holds a zero, swap in a lower row with a nonzero entry there, if there is one. Factor the reordered matrix, and reorder the right side in the same way before solving.

Example The matrix

K=[0213]K = \begin{bmatrix} 0 & 2 \\ 1 & 3 \end{bmatrix}

has a zero in its first pivot position, yet it is invertible. Swapping its rows with the permutation matrix PP that has rows e2⊤\mathbf{e}_2^{\top} and e1⊤\mathbf{e}_1^{\top} gives

PK=[1302],PK = \begin{bmatrix} 1 & 3 \\ 0 & 2 \end{bmatrix},

which is already upper triangular, so L=I2L = I_2 and U=PKU = PK. For b=(4,7)\mathbf{b} = (4, 7) the permuted right side is Pb=(7,4)P\mathbf{b} = (7, 4). The second row gives 2y=42y = 4, so y=2y = 2, and the first gives x+3y=7x + 3y = 7, so x=1x = 1. In the original order the equations are 2y=42y = 4 and x+3y=7x + 3y = 7, and both hold.

Partial pivoting

Definition Partial pivoting is a rule for choosing row swaps during elimination. At step jj, look at the entries in column jj in rows jj through nn of the current matrix, choose one of largest absolute value, and swap its row with row jj. If all of these entries are zero, position (j,j)(j, j) of UU stays zero, so AA is singular, and elimination moves on to the next column. Each swap exchanges three things, the two whole rows of the current matrix, the multipliers already stored in columns 11 through j−1j - 1 of LL for those two rows, and the two positions in the record of row order that builds PP. Every multiplier then has absolute value at most 11. In floating point arithmetic this tends to limit the growth of rounding errors, though it cannot remove the sensitivity of a badly conditioned system.

In plain words Before clearing a column, bring up the row whose entry there is largest in absolute value. When rows move, the multipliers already written in LL move with them, because each multiplier belongs to its row.

Example Factor

M=[021110234].M = \begin{bmatrix} 0 & 2 & 1 \\ 1 & 1 & 0 \\ 2 & 3 & 4 \end{bmatrix}.

In column 1 the candidates are 00, 11 and 22, so swap rows 1 and 3, and the row order becomes 3, 2, 1. The multipliers are ℓ21=12\ell_{21} = \tfrac{1}{2} and ℓ31=0\ell_{31} = 0, and R2→R2−12R1R_2 \to R_2 - \tfrac{1}{2}R_1 gives

[2340−12−2021].\begin{bmatrix} 2 & 3 & 4 \\ 0 & -\tfrac{1}{2} & -2 \\ 0 & 2 & 1 \end{bmatrix}.

In column 2 the candidates are −12-\tfrac{1}{2} and 22, so swap rows 2 and 3, and the row order becomes 3, 1, 2. The stored multipliers in column 1 of LL swap as well, so now ℓ21=0\ell_{21} = 0 and ℓ31=12\ell_{31} = \tfrac{1}{2}. The new multiplier is ℓ32=−12÷2=−14\ell_{32} = -\tfrac{1}{2} \div 2 = -\tfrac{1}{4}, and R3→R3+14R2R_3 \to R_3 + \tfrac{1}{4}R_2 finishes the elimination. The factors are

P=[001100010],L=[10001012−141],U=[23402100−74].\begin{aligned} P &= \begin{bmatrix} 0 & 0 & 1 \\ 1 & 0 & 0 \\ 0 & 1 & 0 \end{bmatrix}, \\[0.8em] L &= \begin{bmatrix} 1 & 0 & 0 \\ 0 & 1 & 0 \\ \tfrac{1}{2} & -\tfrac{1}{4} & 1 \end{bmatrix}, \\[0.8em] U &= \begin{bmatrix} 2 & 3 & 4 \\ 0 & 2 & 1 \\ 0 & 0 & -\tfrac{7}{4} \end{bmatrix}. \end{aligned}

The first two rows of LULU are the first two rows of UU, which are rows 3 and 1 of MM. The third row of LULU is

12[234]−14[021]+[00−74]=[110],\begin{aligned} &\tfrac{1}{2}\begin{bmatrix} 2 & 3 & 4 \end{bmatrix} - \tfrac{1}{4}\begin{bmatrix} 0 & 2 & 1 \end{bmatrix} \\[0.4em] &\quad + \begin{bmatrix} 0 & 0 & -\tfrac{7}{4} \end{bmatrix} \\[0.4em] &\quad = \begin{bmatrix} 1 & 1 & 0 \end{bmatrix}, \end{aligned}

which is row 2 of MM, so PM=LUPM = LU. Had the multiplier 12\tfrac{1}{2} stayed in row 2 of LL, this check would fail. For b=(7,3,20)\mathbf{b} = (7, 3, 20) we get Pb=(20,7,3)P\mathbf{b} = (20, 7, 3), forward substitution gives w=(20,7,−214)\mathbf{w} = (20, 7, -\tfrac{21}{4}), and back-substitution gives x=(1,2,3)\mathbf{x} = (1, 2, 3). In the original order, Mx=(4+3,1+2,2+6+12)=(7,3,20)M\mathbf{x} = (4 + 3, 1 + 2, 2 + 6 + 12) = (7, 3, 20).

Check yourself

  1. Find the LU factorization of the matrix below and use it to solve Ax=(4,14)A\mathbf{x} = (4, 14).
A=[1238]A = \begin{bmatrix} 1 & 2 \\ 3 & 8 \end{bmatrix}
Show the answer

The multiplier is ℓ21=3/1=3\ell_{21} = 3/1 = 3, and R2→R2−3R1R_2 \to R_2 - 3R_1 leaves the upper triangular matrix, so

L=[1031],U=[1202].L = \begin{bmatrix} 1 & 0 \\ 3 & 1 \end{bmatrix}, \qquad U = \begin{bmatrix} 1 & 2 \\ 0 & 2 \end{bmatrix}.

Forward substitution gives w1=4w_1 = 4 and 3⋅4+w2=143 \cdot 4 + w_2 = 14, so w=(4,2)\mathbf{w} = (4, 2). Back-substitution gives 2y=22y = 2, so y=1y = 1, and x+2=4x + 2 = 4, so x=2x = 2. The original equations check, since 2+2=42 + 2 = 4 and 6+8=146 + 8 = 14.

  1. Show that the matrix below has no LU factorization without row swaps, even though it is invertible. Then find PA=LUPA = LU and solve Ax=(3,5)A\mathbf{x} = (3, 5).
A=[0111]A = \begin{bmatrix} 0 & 1 \\ 1 & 1 \end{bmatrix}
Show the answer

Suppose A=LUA = LU with LL unit lower triangular and UU upper triangular. The top left entries give 0=u110 = u_{11}, and the bottom left entries give 1=ℓ21u11=01 = \ell_{21}u_{11} = 0, which is impossible. Swapping the rows gives

PA=[1101],PA = \begin{bmatrix} 1 & 1 \\ 0 & 1 \end{bmatrix},

which is upper triangular, so L=I2L = I_2 and U=PAU = PA. It has two pivots, so AA is invertible. The right side b=(3,5)\mathbf{b} = (3, 5) becomes Pb=(5,3)P\mathbf{b} = (5, 3). Back-substitution gives y=3y = 3 and x+3=5x + 3 = 5, so x=2x = 2. In the original order, 0⋅2+3=30 \cdot 2 + 3 = 3 and 2+3=52 + 3 = 5.

  1. Use partial pivoting to factor the matrix below as PA=LUPA = LU, then solve Ax=(5,11)A\mathbf{x} = (5, 11). What goes wrong if you forget to permute the right side?
A=[1234]A = \begin{bmatrix} 1 & 2 \\ 3 & 4 \end{bmatrix}
Show the answer

In column 1 the candidates are 11 and 33, so swap the rows. The multiplier is ℓ21=13\ell_{21} = \tfrac{1}{3}, and R2→R2−13R1R_2 \to R_2 - \tfrac{1}{3}R_1 turns the second row into [023]\begin{bmatrix} 0 & \tfrac{2}{3} \end{bmatrix}. So

P=[0110],L=[10131],U=[34023].\begin{gathered} P = \begin{bmatrix} 0 & 1 \\ 1 & 0 \end{bmatrix}, \qquad L = \begin{bmatrix} 1 & 0 \\ \tfrac{1}{3} & 1 \end{bmatrix}, \\[0.4em] U = \begin{bmatrix} 3 & 4 \\ 0 & \tfrac{2}{3} \end{bmatrix}. \end{gathered}

The right side b=(5,11)\mathbf{b} = (5, 11) becomes Pb=(11,5)P\mathbf{b} = (11, 5). Forward substitution gives w1=11w_1 = 11 and w2=5−113=43w_2 = 5 - \tfrac{11}{3} = \tfrac{4}{3}. Back-substitution gives 23y=43\tfrac{2}{3}y = \tfrac{4}{3}, so y=2y = 2, and 3x+8=113x + 8 = 11, so x=1x = 1. The original equations check, since 1+4=51 + 4 = 5 and 3+8=113 + 8 = 11.

Forgetting the permutation means solving LUx=(5,11)LU\mathbf{x} = (5, 11), which gives x=(−17,14)\mathbf{x} = (-17, 14). That vector solves PAx=(5,11)PA\mathbf{x} = (5, 11), so it satisfies Ax=(11,5)A\mathbf{x} = (11, 5), the system with its two right sides exchanged.

How this lesson connects

Where this leads in Linear Algebra II