Linear AlgebraMatrix Algebra8 of 9
Matrix Algebra · 8

LU Factorization

When we have to solve Ax=bAx = b for many different right-hand sides bb using the same matrix AA, running Gaussian elimination on AA from scratch every time repeats the exact same work, so we want to save our elimination steps inside a matrix of their own.

1

Saving Elimination Steps in LL and UU

We want to solve the system

x1+2x2+x3=62x1+5x2+5x3=173x1+10x2+17x3=40written as[12125531017]⏟A[x1x2x3]⏟x=[61740]⏟b\displaystyle \begin{gathered} \begin{aligned} x_1 + 2x_2 + x_3 &= 6 \\ 2x_1 + 5x_2 + 5x_3 &= 17 \\ 3x_1 + 10x_2 + 17x_3 &= 40 \end{aligned} \\ \text{written as}\\ \underbrace{\begin{bmatrix} 1 & 2 & 1 \\ 2 & 5 & 5 \\ 3 & 10 & 17 \end{bmatrix}}_{A} \underbrace{\begin{bmatrix} x_1 \\ x_2 \\ x_3 \end{bmatrix}}_{x} = \underbrace{\begin{bmatrix} 6 \\ 17 \\ 40 \end{bmatrix}}_{b} \end{gathered}

by reducing AA to an upper triangular matrix UU and saving the multipliers we subtracted in a lower triangular matrix LL.

The row operation that subtracts m\mult{m} times row jj from row ii can be written as an elimination matrix EijE_{ij} by placing −m\mult{-m} into the (i,j)(i,j) spot of the identity matrix, and its inverse Eij−1E_{ij}^{-1} simply flips −m\mult{-m} to +m\mult{+m} because adding m\mult{m} times row jj back undoes the subtraction:

E21=[100−210001]⏟subtract 2R1 from R2→undo stepE21−1=[100210001]⏟add 2R1 back to R2\displaystyle \begin{aligned} & \underbrace{E_{21} = \begin{bmatrix} 1 & 0 & 0 \\ \mult{-2} & 1 & 0 \\ 0 & 0 & 1 \end{bmatrix}}_{\text{subtract } \mult{2}R_1 \text{ from } R_2} \\[18pt] \xrightarrow{\text{undo step}}\quad & \underbrace{E_{21}^{-1} = \begin{bmatrix} 1 & 0 & 0 \\ \mult{2} & 1 & 0 \\ 0 & 0 & 1 \end{bmatrix}}_{\text{add } \mult{2}R_1 \text{ back to } R_2} \end{aligned}
Saving Elimination Steps in L and U
[12125531017]A[x1x2x3]=[61740]b\underset{\textstyle A}{\begin{bmatrix} 1 & 2 & 1 \\ 2 & 5 & 5 \\ 3 & 10 & 17 \end{bmatrix}} \begin{bmatrix} x_1 \\ x_2 \\ x_3 \end{bmatrix} = \underset{\textstyle b}{\begin{bmatrix} 6 \\ 17 \\ 40 \end{bmatrix}}
66
1717
4040
Text solution
Clear below the first pivotUse the 1\pivot{1} in the (1,1)(1,1) spot to eliminate the 22 and 33 below it by subtracting 2\mult{2} times Row 1 from Row 2 and 3\mult{3} times Row 1 from Row 3.
[12125531017]→R2←R2−2R1[12101331017]→R3←R3−3R1[1210130414]\displaystyle \begin{aligned} & \begin{bmatrix} \pivot{1} & 2 & 1 \\ 2 & 5 & 5 \\ 3 & 10 & 17 \end{bmatrix} \\[18pt] \xrightarrow{R_2 \leftarrow R_2 - \mult{2}R_1}\quad & \begin{bmatrix} \pivot{1} & 2 & 1 \\ 0 & 1 & 3 \\ 3 & 10 & 17 \end{bmatrix} \\[18pt] \xrightarrow{R_3 \leftarrow R_3 - \mult{3}R_1}\quad & \begin{bmatrix} \pivot{1} & 2 & 1 \\ 0 & 1 & 3 \\ 0 & 4 & 14 \end{bmatrix} \end{aligned}
Clear below the second pivotUse the 1\pivot{1} in the (2,2)(2,2) spot to eliminate the 44 below it by subtracting 4\mult{4} times the updated Row 2 from Row 3.
[1210130414]→R3←R3−4R2[121013002]⏟upper triangular U\displaystyle \begin{aligned} & \begin{bmatrix} \pivot{1} & 2 & 1 \\ 0 & \pivot{1} & 3 \\ 0 & 4 & 14 \end{bmatrix} \\[18pt] \xrightarrow{R_3 \leftarrow R_3 - \mult{4}R_2}\quad & \underbrace{\begin{bmatrix} \pivot{1} & 2 & 1 \\ 0 & \pivot{1} & 3 \\ 0 & 0 & \pivot{2} \end{bmatrix}}_{\text{upper triangular } U} \end{aligned}
Move the elimination matrices onto UU to form LLSolving E32E31E21A=UE_{32}E_{31}E_{21}A = U for AA reverses the order into E21−1E31−1E32−1UE_{21}^{-1}E_{31}^{-1}E_{32}^{-1}U, which puts the multipliers 2\mult{2}, 3\mult{3}, and 4\mult{4} directly into the spots they zeroed out.
A=E21−1E31−1E32−1U=[100210001][100010301][100010041][121013002]=[100210341]⏟lower triangular L[121013002]⏟upper triangular U\displaystyle \begin{aligned} A &= E_{21}^{-1}E_{31}^{-1}E_{32}^{-1}U \\ &= \begin{bmatrix} 1 & 0 & 0 \\ \mult{2} & 1 & 0 \\ 0 & 0 & 1 \end{bmatrix} \begin{bmatrix} 1 & 0 & 0 \\ 0 & 1 & 0 \\ \mult{3} & 0 & 1 \end{bmatrix} \\[18pt] &\quad \begin{bmatrix} 1 & 0 & 0 \\ 0 & 1 & 0 \\ 0 & \mult{4} & 1 \end{bmatrix} \begin{bmatrix} \pivot{1} & 2 & 1 \\ 0 & \pivot{1} & 3 \\ 0 & 0 & \pivot{2} \end{bmatrix} \\[18pt] &= \underbrace{\begin{bmatrix} 1 & 0 & 0 \\ \mult{2} & 1 & 0 \\ \mult{3} & \mult{4} & 1 \end{bmatrix}}_{\text{lower triangular } L} \quad\underbrace{\begin{bmatrix} \pivot{1} & 2 & 1 \\ 0 & \pivot{1} & 3 \\ 0 & 0 & \pivot{2} \end{bmatrix}}_{\text{upper triangular } U} \end{aligned}

So A=LUA = LU saves the finished upper triangular matrix in UU and the exact multipliers 2\mult{2}, 3\mult{3}, and 4\mult{4} subtracted during elimination in LL. On a test, you don't need to write out the EE matrices: just start LL with 11s on the diagonal and 00s above it, and put each multiplier straight into the spot it zeros out.

On the A side: E32E31E21A=U\text{On the } A \text{ side: } E_{32}E_{31}E_{21}A = U
Row 1\text{Row 1}
Row 2\text{Row 2}
Row 3\text{Row 3}
−2R1\htmlClass{lc-violet}{-2}R_1
−4R2\htmlClass{lc-violet}{-4}R_2
−3R1\htmlClass{lc-violet}{-3}R_1
(−4)(−2R1)=+8R1−3+8=5, the (3,1) entry of E\begin{aligned} (\htmlClass{lc-violet}{{-4}})(\htmlClass{lc-violet}{{-2}}R_1) &= \htmlClass{lc-orange}{+8R_1} \\ \htmlClass{lc-violet}{{-3}} + \htmlClass{lc-orange}{8} &= \htmlClass{lc-orange}{5}\text{, the } (3,1) \text{ entry of } E \end{aligned}
On the U side: A=LU\text{On the } U \text{ side: } A = LU
UU
1      2      1\htmlClass{lc-blue}{1}\;\;\;2\;\;\;1
0      1      30\;\;\;\htmlClass{lc-blue}{1}\;\;\;3
0      0      20\;\;\;0\;\;\;\htmlClass{lc-blue}{2}
3\htmlClass{lc-violet}{3}
4\htmlClass{lc-violet}{4}
11
3      10      173\;\;\;10\;\;\;17
row 3 of A\text{row 3 of } A
L=[100210341]L = \begin{bmatrix} 1 & 0 & 0 \\ \htmlClass{lc-violet}{2} & 1 & 0 \\ \htmlClass{lc-violet}{3} & \htmlClass{lc-violet}{4} & 1 \end{bmatrix}

On the AA side of the equation, later elimination matrices act on rows that earlier steps already changed, which mixes the multipliers so the (3,1)(3,1) entry of the product E32E31E21E_{32}E_{31}E_{21} becomes −3+8=5\mult{-3} + \trouble{8} = \trouble{5}. Across the equals sign on the UU side, their inverses act in reverse order on the finished rows of UU, so the multipliers 2\mult{2}, 3\mult{3}, and 4\mult{4} go untouched into LL.

On the A side, later elimination steps act on earlier ones and mix the multipliers, while moving the matrices to the U side reverses their order so every multiplier goes straight into L unchanged.
2

Solving Ax=bAx = b with Forward and Back Substitution

Now that AA is factored into LULU, we want to solve our original system

Ax=bforb=[61740]\displaystyle Ax = b \quad\text{for}\quad b = \begin{bmatrix} 6 \\ 17 \\ 40 \end{bmatrix}

without doing row operations on AA again. Replacing AA with LULU lets us name the unknown vector UxUx as y\inter{y} and split the problem into two triangular systems:

L(Ux)⏟y=b⟹Ly=b⏟forward substitutionthenUx=y⏟back substitution\displaystyle {L\underbrace{(Ux)}_{\inter{y}} = b} \quad\Longrightarrow\quad \underbrace{L\inter{y} = b}_{\text{forward substitution}} \quad\text{then}\quad \underbrace{Ux = \inter{y}}_{\text{back substitution}}
Solving Ax = b with Forward and Back Substitution
A=[100210341]L[121013002]U\displaystyle A = \underset{\textstyle L}{\begin{bmatrix} 1 & 0 & 0 \\ \mult{2} & 1 & 0 \\ \mult{3} & \mult{4} & 1 \end{bmatrix}} \underset{\textstyle U}{\begin{bmatrix} \pivot{1} & 2 & 1 \\ 0 & \pivot{1} & 3 \\ 0 & 0 & \pivot{2} \end{bmatrix}}
A x=[61740],x=  ?\displaystyle A\,x = \begin{bmatrix} 6 \\ 17 \\ 40 \end{bmatrix}, \qquad x = \;?
Text solution
Forward substitution (Ly=bL\inter{y} = b from top to bottom)Solve for y1\inter{y_1}, y2\inter{y_2}, and y3\inter{y_3} down the rows of LL.
[100210341][y1y2y3]=[61740]⟹y1=6y2=17−2(6)=5y3=40−3(6)−4(5)=2\displaystyle \begin{aligned} & \begin{bmatrix} 1 & 0 & 0 \\ \mult{2} & 1 & 0 \\ \mult{3} & \mult{4} & 1 \end{bmatrix} \begin{bmatrix} \inter{y_1} \\ \inter{y_2} \\ \inter{y_3} \end{bmatrix} = \begin{bmatrix} 6 \\ 17 \\ 40 \end{bmatrix} \\[18pt] \Longrightarrow\quad & \begin{aligned} \inter{y_1} &= \inter{6} \\ \inter{y_2} &= 17 - \mult{2}(\inter{6}) = \inter{5} \\ \inter{y_3} &= 40 - \mult{3}(\inter{6}) - \mult{4}(\inter{5}) = \inter{2} \end{aligned} \end{aligned}
Back substitution (Ux=yUx = \inter{y} from bottom to top)Use y=[652]\inter{y} = \inter{\begin{bmatrix} 6 \\ 5 \\ 2 \end{bmatrix}} as the right-hand side and solve for x3x_3, x2x_2, and x1x_1 up the rows of UU.
[121013002][x1x2x3]=[652]⟹x3=22=1x2=5−3(1)=2x1=6−2(2)−1(1)=1\displaystyle \begin{aligned} & \begin{bmatrix} \pivot{1} & 2 & 1 \\ 0 & \pivot{1} & 3 \\ 0 & 0 & \pivot{2} \end{bmatrix} \begin{bmatrix} x_1 \\ x_2 \\ x_3 \end{bmatrix} = \begin{bmatrix} \inter{6} \\ \inter{5} \\ \inter{2} \end{bmatrix} \\[18pt] \Longrightarrow\quad & \begin{aligned} x_3 &= \frac{\inter{2}}{\pivot{2}} = 1 \\ x_2 &= \inter{5} - 3(1) = 2 \\ x_1 &= \inter{6} - 2(2) - 1(1) = 1 \end{aligned} \end{aligned}

So x=[121]x = \begin{bmatrix} 1 \\ 2 \\ 1 \end{bmatrix} solves Ax=bAx = b, and the intermediate vector y=[652]\inter{y} = \inter{\begin{bmatrix} 6 \\ 5 \\ 2 \end{bmatrix}} is the exact right-hand side we would have gotten by applying the row operations on AA to bb.

Whenever the right-hand side bb changes, AA, LL, and UU stay completely fixed while Ly=bL\inter{y} = b runs the saved elimination steps on bb from top to bottom and Ux=yUx = \inter{y} solves for the new xx from bottom to top.

Once the matrix is factored, you can solve for any new load in two quick passes without redoing elimination.
3

Negative and Fractional Multipliers

In the first example, both pivots we eliminated with were 1\pivot{1} and every step subtracted a positive whole number. Now let's factor

A=[242−4−62157]\displaystyle A = \begin{bmatrix} 2 & 4 & 2 \\ -4 & -6 & 2 \\ 1 & 5 & 7 \end{bmatrix}

into A=LUA = LU, where the pivots are not 11 and elimination requires adding a row or subtracting fractions.

Negative and Fractional Multipliers
2\htmlClass{lc-blue}{2}
44
22
−4-4
−6-6
22
11
55
77
==
11
0\htmlClass{lc-mute}{0}
0\htmlClass{lc-mute}{0}
11
0\htmlClass{lc-mute}{0}
11
??
AA
LL
UU
Text solution
Clear below the first pivot 2\pivot{2}Add 2\mult{2} times Row 1 to Row 2 (which is subtracting −2\mult{-2} times Row 1, so L21=−2\mult{L_{21}} = \mult{-2}) and subtract 12\mult{\frac{1}{2}} times Row 1 from Row 3 (so L31=12\mult{L_{31}} = \mult{\frac{1}{2}}).
[242−4−62157]→R2←R2−(−2)R1[242026157]→R3←R3−12R1[242026036]\displaystyle \begin{aligned} & \begin{bmatrix} \pivot{2} & 4 & 2 \\ -4 & -6 & 2 \\ 1 & 5 & 7 \end{bmatrix} \\[18pt] \xrightarrow{R_2 \leftarrow R_2 - \mult{(-2)}R_1}\quad & \begin{bmatrix} \pivot{2} & 4 & 2 \\ 0 & 2 & 6 \\ 1 & 5 & 7 \end{bmatrix} \\[18pt] \xrightarrow{R_3 \leftarrow R_3 - \mult{\frac{1}{2}}R_1}\quad & \begin{bmatrix} \pivot{2} & 4 & 2 \\ 0 & 2 & 6 \\ 0 & 3 & 6 \end{bmatrix} \end{aligned}
Clear below the second pivot 2\pivot{2}Subtract 32\mult{\frac{3}{2}} times the updated Row 2 from Row 3 (so L32=32\mult{L_{32}} = \mult{\frac{3}{2}}) to reach UU.
[242026036]→R3←R3−32R2[24202600−3]⏟U\displaystyle \begin{aligned} & \begin{bmatrix} \pivot{2} & 4 & 2 \\ 0 & \pivot{2} & 6 \\ 0 & 3 & 6 \end{bmatrix} \\[18pt] \xrightarrow{R_3 \leftarrow R_3 - \mult{\frac{3}{2}}R_2}\quad & \underbrace{\begin{bmatrix} \pivot{2} & 4 & 2 \\ 0 & \pivot{2} & 6 \\ 0 & 0 & \pivot{-3} \end{bmatrix}}_{U} \end{aligned}
Write the multipliers in LLPut −2\mult{-2}, 12\mult{\frac{1}{2}}, and 32\mult{\frac{3}{2}} into the positions they zeroed out.
[242−4−62157]=[100−21012321]⏟L[24202600−3]⏟U\displaystyle \begin{bmatrix} 2 & 4 & 2 \\ -4 & -6 & 2 \\ 1 & 5 & 7 \end{bmatrix} = \underbrace{\begin{bmatrix} 1 & 0 & 0 \\ \mult{-2} & 1 & 0 \\ \mult{\frac{1}{2}} & \mult{\frac{3}{2}} & 1 \end{bmatrix}}_{L} \underbrace{\begin{bmatrix} \pivot{2} & 4 & 2 \\ 0 & \pivot{2} & 6 \\ 0 & 0 & \pivot{-3} \end{bmatrix}}_{U}

So A=LUA = LU works the same way with negative and fractional multipliers, and multiplying the first column of LL by the first pivot 2\pivot{2} in UU immediately rebuilds the first column [2−41]\begin{bmatrix} 2 \\ -4 \\ 1 \end{bmatrix} of AA.

To get the sign and fraction right every time, divide the entry you are eliminating by the pivot you are using:

Lij=entry being eliminated in row ipivot being used in row j\displaystyle \boxed{\mult{L_{ij}} = \frac{\text{entry being eliminated in row } i}{\pivot{\text{pivot being used in row } j}}}
4

Row Swaps and PA=LUPA = LU

Dividing by the pivot works whenever the pivot is nonzero, but elimination can put a 0\trouble{0} into a pivot position. We want to factor AA and solve

[121245376]⏟A[x1x2x3]=[51622]⏟b\displaystyle \underbrace{\begin{bmatrix} 1 & 2 & 1 \\ 2 & 4 & 5 \\ 3 & 7 & 6 \end{bmatrix}}_{A} \begin{bmatrix} x_1 \\ x_2 \\ x_3 \end{bmatrix} = \underbrace{\begin{bmatrix} 5 \\ 16 \\ 22 \end{bmatrix}}_{b}

where clearing the first column leaves a 0\trouble{0} in the (2,2)(2,2) pivot spot.

To move a nonzero number into a pivot spot, we swap rows using a permutation matrix PP, which is the identity matrix with the exact same rows swapped:

I=[100010001]→swap Row 2 and Row 3P=[100001010]⏟permutation matrix\displaystyle \begin{aligned} & I = \begin{bmatrix} 1 & 0 & 0 \\ 0 & 1 & 0 \\ 0 & 0 & 1 \end{bmatrix} \\[18pt] \xrightarrow{\text{swap Row 2 and Row 3}}\quad & \underbrace{P = \begin{bmatrix} 1 & 0 & 0 \\ 0 & 0 & 1 \\ 0 & 1 & 0 \end{bmatrix}}_{\text{permutation matrix}} \end{aligned}
Row Swaps and PA = LU
00
0\htmlClass{lc-orange}{0}
00
2\htmlClass{lc-violet}{2}
3\htmlClass{lc-violet}{3}
1\htmlClass{lc-blue}{1}
22
11
00
0\htmlClass{lc-orange}{0}
33
00
11
33
R2↔R3R_2 \leftrightarrow R_3
3\htmlClass{lc-violet}{3}
2\htmlClass{lc-violet}{2}
1\htmlClass{lc-blue}{1}
22
11
00
1\htmlClass{lc-blue}{1}
33
00
00
3\htmlClass{lc-blue}{3}
LL
LL
UU
Text solution
Clear below the first pivotSubtract 2\mult{2} times Row 1 from Row 2 (multiplier 2\mult{2}) and 3\mult{3} times Row 1 from Row 3 (multiplier 3\mult{3}), which leaves a 0\trouble{0} in the (2,2)(2,2) pivot spot.
[121245376]→R2←R2−2R1[121003376]→R3←R3−3R1[121003013]\displaystyle \begin{aligned} & \begin{bmatrix} \pivot{1} & 2 & 1 \\ 2 & 4 & 5 \\ 3 & 7 & 6 \end{bmatrix} \\[18pt] \xrightarrow{R_2 \leftarrow R_2 - \mult{2}R_1}\quad & \begin{bmatrix} \pivot{1} & 2 & 1 \\ 0 & \trouble{0} & 3 \\ 3 & 7 & 6 \end{bmatrix} \\[18pt] \xrightarrow{R_3 \leftarrow R_3 - \mult{3}R_1}\quad & \begin{bmatrix} \pivot{1} & 2 & 1 \\ 0 & \trouble{0} & 3 \\ 0 & 1 & 3 \end{bmatrix} \end{aligned}
Swap Row 2 and Row 3 to form PP, LL, and UUSwapping Row 2 and Row 3 puts 1\pivot{1} into the (2,2)(2,2) pivot spot to finish UU, swaps the already-recorded multipliers 2\mult{2} and 3\mult{3} in the first column of LL, and leaves L32=0\mult{L_{32}} = \mult{0} since the (3,2)(3,2) entry is already 00.
[100001010]⏟P[121245376]⏟A=[100310201]⏟L[121013003]⏟U\displaystyle \underbrace{\begin{bmatrix} 1 & 0 & 0 \\ 0 & 0 & 1 \\ 0 & 1 & 0 \end{bmatrix}}_{P} \underbrace{\begin{bmatrix} 1 & 2 & 1 \\ 2 & 4 & 5 \\ 3 & 7 & 6 \end{bmatrix}}_{A} = \underbrace{\begin{bmatrix} 1 & 0 & 0 \\ \mult{3} & 1 & 0 \\ \mult{2} & \mult{0} & 1 \end{bmatrix}}_{L} \underbrace{\begin{bmatrix} \pivot{1} & 2 & 1 \\ 0 & \pivot{1} & 3 \\ 0 & 0 & \pivot{3} \end{bmatrix}}_{U}
Swap bb and run forward substitution (Ly=PbL\inter{y} = Pb)Swap Row 2 and Row 3 of bb to match the swap on AA, then solve Ly=PbL\inter{y} = Pb from top to bottom.
Pb=[52216],[100310201][y1y2y3]=[52216]⟹y1=5y2=22−3(5)=7y3=16−2(5)−0(7)=6\displaystyle \begin{aligned} & Pb = \begin{bmatrix} 5 \\ 22 \\ 16 \end{bmatrix}, \\[18pt] & \begin{bmatrix} 1 & 0 & 0 \\ \mult{3} & 1 & 0 \\ \mult{2} & \mult{0} & 1 \end{bmatrix} \begin{bmatrix} \inter{y_1} \\ \inter{y_2} \\ \inter{y_3} \end{bmatrix} = \begin{bmatrix} 5 \\ 22 \\ 16 \end{bmatrix} \\[18pt] \Longrightarrow\quad & \begin{aligned} \inter{y_1} &= \inter{5} \\ \inter{y_2} &= 22 - \mult{3}(\inter{5}) = \inter{7} \\ \inter{y_3} &= 16 - \mult{2}(\inter{5}) - \mult{0}(\inter{7}) = \inter{6} \end{aligned} \end{aligned}
Back substitution (Ux=yUx = \inter{y})Solve Ux=yUx = \inter{y} from the bottom row up.
[121013003][x1x2x3]=[576]⟹x3=63=2x2=7−3(2)=1x1=5−2(1)−1(2)=1\displaystyle \begin{aligned} & \begin{bmatrix} \pivot{1} & 2 & 1 \\ 0 & \pivot{1} & 3 \\ 0 & 0 & \pivot{3} \end{bmatrix} \begin{bmatrix} x_1 \\ x_2 \\ x_3 \end{bmatrix} = \begin{bmatrix} \inter{5} \\ \inter{7} \\ \inter{6} \end{bmatrix} \\[18pt] \Longrightarrow\quad & \begin{aligned} x_3 &= \frac{\inter{6}}{\pivot{3}} = 2 \\ x_2 &= \inter{7} - 3(2) = 1 \\ x_1 &= \inter{5} - 2(1) - 1(2) = 1 \end{aligned} \end{aligned}

So x=[112]x = \begin{bmatrix} 1 \\ 1 \\ 2 \end{bmatrix} solves Ax=bAx = b, with PP applying the same row swap to AA and bb before we use LL and UU to solve the two triangular systems.

When two rows swap to replace a zero pivot, the matching rows of the identity matrix swap to form PP, the entries of bb swap into PbPb, and the multipliers already recorded in LL swap along with the rows they came from so that PA=LUPA = LU.

Swapping two rows to fix a zero pivot moves their multipliers, their permutation rows, and their right-hand side numbers right along with them.

Key concepts

If you only ever need to solve Ax=bAx = b for a single vector bb, ordinary elimination on AA and bb together does the same arithmetic without building LL. We factor AA into LL and UU when AA stays fixed across many different right-hand sides bb, or when we want a matrix record of the elimination steps.

Without row swaps, Gaussian elimination factors A=LUA = LU. As you reduce AA to the upper triangular matrix UU, start the lower triangular matrix LL with 11s on the diagonal and put each multiplier

Lij\displaystyle \mult{L_{ij}} =entry being eliminatedpivot\displaystyle = \frac{\text{entry being eliminated}}{\pivot{\text{pivot}}}

straight into the (i,j)(i,j) spot it zeros out. Because L=E21−1E31−1E32−1L = E_{21}^{-1}E_{31}^{-1}E_{32}^{-1} rebuilds AA from the finished rows of UU, the multipliers never mix the way they do in the forward product E32E31E21E_{32}E_{31}E_{21}. Watch the sign whenever you add a row: eliminating −4-4 with the pivot 2\pivot{2} via R2←R2+2R1R_2 \leftarrow R_2 + \mult{2}R_1 means you subtracted −2R1\mult{-2}R_1, so L21=−42=−2\mult{L_{21}} = \frac{-4}{\pivot{2}} = \mult{-2}.

If a 0\trouble{0} appears in a pivot spot (such as the (2,2)(2,2) entry in [121003013]\begin{bmatrix} \pivot{1} & 2 & 1 \\ 0 & \trouble{0} & 3 \\ 0 & 1 & 3 \end{bmatrix}), swap that row with a row below it that has a nonzero entry in that column. Record the same swap on the identity matrix to get PP, and swap the multipliers already recorded in earlier columns of LL (so L21=2\mult{L_{21}} = \mult{2} and L31=3\mult{L_{31}} = \mult{3} trade places to become L21=3\mult{L_{21}} = \mult{3} and L31=2\mult{L_{31}} = \mult{2}), giving PA=LUPA = LU. If the swap already leaves a 00 below the new pivot, no elimination step is needed there and L32=0\mult{L_{32}} = \mult{0}.

Once AA is factored, solve for any bb in two triangular steps without doing row operations on AA again: swap bb into PbPb if rows were swapped, solve Ly=bL\inter{y} = b (or Ly=PbL\inter{y} = Pb) from top to bottom for y\inter{y}, and solve Ux=yUx = \inter{y} from bottom to top for xx.

5

Practice

1

Given the factorization A=LUA = LU with

L=[100210−131]andU=[13−1012004],\displaystyle \begin{aligned} L &= \begin{bmatrix} 1 & 0 & 0 \\ \mult{2} & 1 & 0 \\ \mult{-1} & \mult{3} & 1 \end{bmatrix} \quad\text{and}\\ U &= \begin{bmatrix} \pivot{1} & 3 & -1 \\ 0 & \pivot{1} & 2 \\ 0 & 0 & \pivot{4} \end{bmatrix}, \end{aligned}

solve Ax=bAx = b for b=[41113]b = \begin{bmatrix} 4 \\ 11 \\ 13 \end{bmatrix} by first solving Ly=bL\inter{y} = b and then solving Ux=yUx = \inter{y}.

Start at the top row of Ly=bL\inter{y} = b where y1\inter{y_1} is the only unknown, then use your finished vector y\inter{y} as the right-hand side of Ux=yUx = \inter{y} starting from the bottom row.

Solve Ly=bL\inter{y} = b from top to bottom:
[100210−131][y1y2y3]=[41113]⟹y1=42(4)+y2=11  ⟹  y2=11−8=3−1(4)+3(3)+y3=13  ⟹  y3=13+4−9=8\displaystyle \begin{aligned} & \begin{bmatrix} 1 & 0 & 0 \\ \mult{2} & 1 & 0 \\ \mult{-1} & \mult{3} & 1 \end{bmatrix} \begin{bmatrix} \inter{y_1} \\ \inter{y_2} \\ \inter{y_3} \end{bmatrix} = \begin{bmatrix} 4 \\ 11 \\ 13 \end{bmatrix} \\[18pt] & \begin{aligned} \Longrightarrow\quad \inter{y_1} &= \inter{4} \\[6pt] & \mult{2}(\inter{4}) + \inter{y_2} = 11 \\ \;\Longrightarrow\; \inter{y_2} &= 11 - 8 = \inter{3} \\[6pt] & \mult{-1}(\inter{4}) + \mult{3}(\inter{3}) + \inter{y_3} = 13 \\ \;\Longrightarrow\; \inter{y_3} &= 13 + 4 - 9 = \inter{8} \end{aligned} \end{aligned}
(Watch the minus sign on L31=−1\mult{L_{31}} = \mult{-1} in the third row: missing the minus sign gives 4+9+y3=13  ⟹  y3=04 + 9 + \inter{y_3} = 13 \implies \inter{y_3} = 0, which leads to the wrong solution x=[−530]x = \begin{bmatrix} -5 \\ 3 \\ 0 \end{bmatrix}.)
Now solve Ux=yUx = \inter{y} from bottom to top using y=[438]\inter{y} = \inter{\begin{bmatrix} 4 \\ 3 \\ 8 \end{bmatrix}}:
[13−1012004][x1x2x3]=[438]⟹4x3=8  ⟹  x3=2x2+2(2)=3  ⟹  x2=3−4=−1x1+3(−1)−1(2)=4  ⟹  x1=4+3+2=9\displaystyle \begin{aligned} & \begin{bmatrix} \pivot{1} & 3 & -1 \\ 0 & \pivot{1} & 2 \\ 0 & 0 & \pivot{4} \end{bmatrix} \begin{bmatrix} x_1 \\ x_2 \\ x_3 \end{bmatrix} = \begin{bmatrix} \inter{4} \\ \inter{3} \\ \inter{8} \end{bmatrix} \\[18pt] & \begin{aligned} \Longrightarrow\quad & \pivot{4}x_3 = \inter{8} \\ \;\Longrightarrow\; x_3 &= 2 \\ & x_2 + 2(2) = \inter{3} \\ \;\Longrightarrow\; x_2 &= 3 - 4 = -1 \\ & x_1 + 3(-1) - 1(2) = \inter{4} \\ \;\Longrightarrow\; x_1 &= 4 + 3 + 2 = 9 \end{aligned} \end{aligned}
y=[438],x=[9−12]\displaystyle \inter{y} = \begin{bmatrix} 4 \\ 3 \\ 8 \end{bmatrix}, \qquad x = \begin{bmatrix} 9 \\ -1 \\ 2 \end{bmatrix}
2

Factor A=[2−24−69−111−75]A = \begin{bmatrix} 2 & -2 & 4 \\ -6 & 9 & -11 \\ 1 & -7 & 5 \end{bmatrix} into A=LUA = LU.

Divide each entry being eliminated by the pivot you are using, and pay close attention to the sign when you add a multiple of a pivot row to clear a negative entry.

Clear below the first pivot 2\pivot{2} using L21=−62=−3\mult{L_{21}} = \frac{-6}{\pivot{2}} = \mult{-3} and L31=12\mult{L_{31}} = \mult{\frac{1}{2}}:
[2−24−69−111−75]→R2←R2−(−3)R1[2−240311−75]→R3←R3−12R1[2−240310−63]\displaystyle \begin{aligned} & \begin{bmatrix} \pivot{2} & -2 & 4 \\ -6 & 9 & -11 \\ 1 & -7 & 5 \end{bmatrix} \\[18pt] \xrightarrow{R_2 \leftarrow R_2 - \mult{(-3)}R_1}\quad & \begin{bmatrix} \pivot{2} & -2 & 4 \\ 0 & 3 & 1 \\ 1 & -7 & 5 \end{bmatrix} \\[18pt] \xrightarrow{R_3 \leftarrow R_3 - \mult{\frac{1}{2}}R_1}\quad & \begin{bmatrix} \pivot{2} & -2 & 4 \\ 0 & 3 & 1 \\ 0 & -6 & 3 \end{bmatrix} \end{aligned}
Clear below the second pivot 3\pivot{3} using L32=−63=−2\mult{L_{32}} = \frac{-6}{\pivot{3}} = \mult{-2}:
[2−240310−63]→R3←R3−(−2)R2[2−24031005]\displaystyle \begin{aligned} & \begin{bmatrix} \pivot{2} & -2 & 4 \\ 0 & \pivot{3} & 1 \\ 0 & -6 & 3 \end{bmatrix} \\[18pt] \xrightarrow{R_3 \leftarrow R_3 - \mult{(-2)}R_2}\quad & \begin{bmatrix} \pivot{2} & -2 & 4 \\ 0 & \pivot{3} & 1 \\ 0 & 0 & \pivot{5} \end{bmatrix} \end{aligned}
(Because we added 3R1\mult{3}R_1 and 2R2\mult{2}R_2 during elimination, the multipliers subtracted are −3\mult{-3} and −2\mult{-2}; writing +3+3 and +2+2 in LL is the most common mistake and gives the wrong matrix [1003101221]\begin{bmatrix} 1 & 0 & 0 \\ 3 & 1 & 0 \\ \frac{1}{2} & 2 & 1 \end{bmatrix}.)
L=[100−31012−21],U=[2−24031005]\displaystyle L = \begin{bmatrix} 1 & 0 & 0 \\ -3 & 1 & 0 \\ \frac{1}{2} & -2 & 1 \end{bmatrix}, \qquad U = \begin{bmatrix} 2 & -2 & 4 \\ 0 & 3 & 1 \\ 0 & 0 & 5 \end{bmatrix}
3

Suppose three elimination steps reduce AA to UU via E32E31E21A=UE_{32}E_{31}E_{21}A = U, where

E21=[100−310001],E31=[100010−101],E32=[1000100−21].\displaystyle \begin{aligned} E_{21} &= \begin{bmatrix} 1 & 0 & 0 \\ \mult{-3} & 1 & 0 \\ 0 & 0 & 1 \end{bmatrix}, \\[18pt] E_{31} &= \begin{bmatrix} 1 & 0 & 0 \\ 0 & 1 & 0 \\ \mult{-1} & 0 & 1 \end{bmatrix}, \\[18pt] E_{32} &= \begin{bmatrix} 1 & 0 & 0 \\ 0 & 1 & 0 \\ 0 & \mult{-2} & 1 \end{bmatrix}. \end{aligned}

Find the single combined forward matrix E=E32E31E21E = E_{32}E_{31}E_{21} and the lower triangular matrix LL in A=LUA = LU, and explain why the (3,1)(3,1) entry of EE is not simply −L31-\mult{L_{31}}.

Multiply E31E21E_{31}E_{21} first and then multiply on the left by E32E_{32}; to find LL, invert each elimination matrix and multiply them in the reverse order E21−1E31−1E32−1E_{21}^{-1}E_{31}^{-1}E_{32}^{-1}.

Multiply the forward elimination matrices in order from right to left:
E31E21=[100010−101][100−310001]=[100−310−101]\displaystyle E_{31}E_{21} = \begin{bmatrix} 1 & 0 & 0 \\ 0 & 1 & 0 \\ \mult{-1} & 0 & 1 \end{bmatrix} \begin{bmatrix} 1 & 0 & 0 \\ \mult{-3} & 1 & 0 \\ 0 & 0 & 1 \end{bmatrix} = \begin{bmatrix} 1 & 0 & 0 \\ \mult{-3} & 1 & 0 \\ \mult{-1} & 0 & 1 \end{bmatrix}
E=E32(E31E21)=[1000100−21][100−310−101]=[100−3105−21]\displaystyle E = E_{32}(E_{31}E_{21}) = \begin{bmatrix} 1 & 0 & 0 \\ 0 & 1 & 0 \\ 0 & \mult{-2} & 1 \end{bmatrix} \begin{bmatrix} 1 & 0 & 0 \\ \mult{-3} & 1 & 0 \\ \mult{-1} & 0 & 1 \end{bmatrix} = \begin{bmatrix} 1 & 0 & 0 \\ \mult{-3} & 1 & 0 \\ \trouble{5} & \mult{-2} & 1 \end{bmatrix}
(Don't just copy −3\mult{-3}, −1\mult{-1}, and −2\mult{-2} into EE to get [100−310−1−21]\begin{bmatrix} 1 & 0 & 0 \\ -3 & 1 & 0 \\ -1 & -2 & 1 \end{bmatrix}: the bottom row of E32E_{32} multiplies the first column of E31E21E_{31}E_{21} to give (0)(1)+(−2)(−3)+(1)(−1)=5(0)(1) + \trouble{(-2)(-3)} + (1)(-1) = \trouble{5}.)
Now invert each elimination matrix and multiply in reverse order to get LL:
L=E21−1E31−1E32−1=[100310001][100010101][100010021]=[100310121]\displaystyle L = E_{21}^{-1}E_{31}^{-1}E_{32}^{-1} = \begin{bmatrix} 1 & 0 & 0 \\ \mult{3} & 1 & 0 \\ 0 & 0 & 1 \end{bmatrix} \begin{bmatrix} 1 & 0 & 0 \\ 0 & 1 & 0 \\ \mult{1} & 0 & 1 \end{bmatrix} \begin{bmatrix} 1 & 0 & 0 \\ 0 & 1 & 0 \\ 0 & \mult{2} & 1 \end{bmatrix} = \begin{bmatrix} 1 & 0 & 0 \\ \mult{3} & 1 & 0 \\ \mult{1} & \mult{2} & 1 \end{bmatrix}
(Be sure to reverse the order to E21−1E31−1E32−1E_{21}^{-1}E_{31}^{-1}E_{32}^{-1}; multiplying the inverses in the forward order E32−1E31−1E21−1E_{32}^{-1}E_{31}^{-1}E_{21}^{-1} mixes the multipliers so the (3,1)(3,1) entry becomes 1+(2)(3)=7\mult{1} + \trouble{(2)(3)} = \trouble{7}.)
In EE, subtracting 2\mult{2} times the updated Row 2 from Row 3 also subtracts 2\mult{2} times (−3 of Row 1)(\mult{-3}\text{ of Row 1}), which adds 6\trouble{6} of Row 1 to the −1\mult{-1} of Row 1 from E31E_{31} to produce 5\trouble{5}; in L=E21−1E31−1E32−1L = E_{21}^{-1}E_{31}^{-1}E_{32}^{-1}, the inverse order rebuilds AA directly from the finished rows of UU so the multipliers 3\mult{3}, 1\mult{1}, and 2\mult{2} do not mix:
E=[100−3105−21],L=[100310121]\displaystyle E = \begin{bmatrix} 1 & 0 & 0 \\ -3 & 1 & 0 \\ 5 & -2 & 1 \end{bmatrix}, \qquad L = \begin{bmatrix} 1 & 0 & 0 \\ 3 & 1 & 0 \\ 1 & 2 & 1 \end{bmatrix}
4

Factor A=[132267−1−12]A = \begin{bmatrix} 1 & 3 & 2 \\ 2 & 6 & 7 \\ -1 & -1 & 2 \end{bmatrix} into PA=LUPA = LU, and use the factorization to solve Ax=bAx = b for b=[7231]b = \begin{bmatrix} 7 \\ 23 \\ 1 \end{bmatrix}.

After clearing the first column, look at the (2,2)(2,2) pivot spot. When you swap rows, remember what must happen to the multipliers already recorded in the first column of LL and to the entries of bb.

Clear below the first pivot 1\pivot{1} using multipliers 2\mult{2} in Row 2 and −1\mult{-1} in Row 3:
[132267−1−12]→R2←R2−2R1[132003−1−12]→R3←R3−(−1)R1[132003024]\displaystyle \begin{aligned} & \begin{bmatrix} \pivot{1} & 3 & 2 \\ 2 & 6 & 7 \\ -1 & -1 & 2 \end{bmatrix} \\[18pt] \xrightarrow{R_2 \leftarrow R_2 - \mult{2}R_1}\quad & \begin{bmatrix} \pivot{1} & 3 & 2 \\ 0 & \trouble{0} & 3 \\ -1 & -1 & 2 \end{bmatrix} \\[18pt] \xrightarrow{R_3 \leftarrow R_3 - \mult{(-1)}R_1}\quad & \begin{bmatrix} \pivot{1} & 3 & 2 \\ 0 & \trouble{0} & 3 \\ 0 & 2 & 4 \end{bmatrix} \end{aligned}
Since a 0\trouble{0} is in the (2,2)(2,2) pivot spot, swap Row 2 and Row 3 to get UU, swap Row 2 and Row 3 of II to get PP, and swap the saved multipliers 2\mult{2} and −1\mult{-1} in the first column of LL:
P=[100001010],L=[100−110201],U=[132024003]\displaystyle P = \begin{bmatrix} 1 & 0 & 0 \\ 0 & 0 & 1 \\ 0 & 1 & 0 \end{bmatrix}, \qquad L = \begin{bmatrix} 1 & 0 & 0 \\ \mult{-1} & 1 & 0 \\ \mult{2} & \mult{0} & 1 \end{bmatrix}, \qquad U = \begin{bmatrix} \pivot{1} & 3 & 2 \\ 0 & \pivot{2} & 4 \\ 0 & 0 & \pivot{3} \end{bmatrix}
(Don't leave the first-column multipliers unswapped as L21=2\mult{L_{21}} = \mult{2} and L31=−1\mult{L_{31}} = \mult{-1}, which would lead to y=[7−1330]\inter{y} = \begin{bmatrix} 7 \\ -13 \\ 30 \end{bmatrix} and x=[1332−53210]x = \begin{bmatrix} \frac{133}{2} \\ -\frac{53}{2} \\ 10 \end{bmatrix}.)
Swap Row 2 and Row 3 of bb to form PbPb, then solve Ly=PbL\inter{y} = Pb from top to bottom:
Pb=[7123],[100−110201][y1y2y3]=[7123]⟹y1=7y2=1−(−1)(7)=8y3=23−2(7)−0(8)=9\displaystyle \begin{aligned} & Pb = \begin{bmatrix} 7 \\ 1 \\ 23 \end{bmatrix}, \\[18pt] & \begin{bmatrix} 1 & 0 & 0 \\ \mult{-1} & 1 & 0 \\ \mult{2} & \mult{0} & 1 \end{bmatrix} \begin{bmatrix} \inter{y_1} \\ \inter{y_2} \\ \inter{y_3} \end{bmatrix} = \begin{bmatrix} 7 \\ 1 \\ 23 \end{bmatrix} \\[18pt] \Longrightarrow\quad & \begin{aligned} \inter{y_1} &= \inter{7} \\ \inter{y_2} &= 1 - (\mult{-1})(\inter{7}) = \inter{8} \\ \inter{y_3} &= 23 - \mult{2}(\inter{7}) - \mult{0}(\inter{8}) = \inter{9} \end{aligned} \end{aligned}
(Remember to swap bb into PbPb first; solving Ly=bL\inter{y} = b with the unswapped b=[7231]b = \begin{bmatrix} 7 \\ 23 \\ 1 \end{bmatrix} gives y=[730−13]\inter{y} = \begin{bmatrix} 7 \\ 30 \\ -13 \end{bmatrix} and x=[−1663713−133]x = \begin{bmatrix} -\frac{166}{3} \\ \frac{71}{3} \\ -\frac{13}{3} \end{bmatrix}.)
Solve Ux=yUx = \inter{y} from bottom to top:
[132024003][x1x2x3]=[789]⟹3x3=9  ⟹  x3=32x2+4(3)=8  ⟹  x2=−2x1+3(−2)+2(3)=7  ⟹  x1=7\displaystyle \begin{aligned} & \begin{bmatrix} \pivot{1} & 3 & 2 \\ 0 & \pivot{2} & 4 \\ 0 & 0 & \pivot{3} \end{bmatrix} \begin{bmatrix} x_1 \\ x_2 \\ x_3 \end{bmatrix} = \begin{bmatrix} \inter{7} \\ \inter{8} \\ \inter{9} \end{bmatrix} \\[18pt] & \begin{aligned} \Longrightarrow\quad & \pivot{3}x_3 = \inter{9} \\ \;\Longrightarrow\; x_3 &= 3 \\ & \pivot{2}x_2 + 4(3) = \inter{8} \\ \;\Longrightarrow\; x_2 &= -2 \\ & x_1 + 3(-2) + 2(3) = \inter{7} \\ \;\Longrightarrow\; x_1 &= 7 \end{aligned} \end{aligned}
P=[100001010],L=[100−110201],U=[132024003],Pb=[7123],y=[789],x=[7−23]\displaystyle P = \begin{bmatrix} 1 & 0 & 0 \\ 0 & 0 & 1 \\ 0 & 1 & 0 \end{bmatrix}, \quad L = \begin{bmatrix} 1 & 0 & 0 \\ -1 & 1 & 0 \\ 2 & 0 & 1 \end{bmatrix}, \quad U = \begin{bmatrix} 1 & 3 & 2 \\ 0 & 2 & 4 \\ 0 & 0 & 3 \end{bmatrix}, \quad Pb = \begin{bmatrix} 7 \\ 1 \\ 23 \end{bmatrix}, \quad \inter{y} = \begin{bmatrix} 7 \\ 8 \\ 9 \end{bmatrix}, \quad x = \begin{bmatrix} 7 \\ -2 \\ 3 \end{bmatrix}
5

Elimination with no row swaps reduces a 3×33\times 3 matrix AA to

U=[21−1032004].\displaystyle U = \begin{bmatrix} \pivot{2} & 1 & -1 \\ 0 & \pivot{3} & 2 \\ 0 & 0 & \pivot{4} \end{bmatrix}.

If the bottom row of AA is [6159]\begin{bmatrix} 6 & 15 & 9 \end{bmatrix}, find the bottom row [L31L321]\begin{bmatrix} \mult{L_{31}} & \mult{L_{32}} & 1 \end{bmatrix} of LL without knowing the first two rows of AA.

Use A=LUA = LU: how does the bottom row of LL combine the three rows of UU to rebuild the bottom row of AA?

In A=LUA = LU, the bottom row [L31L321]\begin{bmatrix} \mult{L_{31}} & \mult{L_{32}} & 1 \end{bmatrix} of LL rebuilds the bottom row of AA as a combination of the rows of UU:
L31[21−1]+L32[032]+1[004]=[6159]\displaystyle \mult{L_{31}}\begin{bmatrix} \pivot{2} & 1 & -1 \end{bmatrix} + \mult{L_{32}}\begin{bmatrix} 0 & \pivot{3} & 2 \end{bmatrix} + 1\begin{bmatrix} 0 & 0 & \pivot{4} \end{bmatrix} = \begin{bmatrix} 6 & 15 & 9 \end{bmatrix}
Match the first entries to find L31\mult{L_{31}}, then match the second entries to find L32\mult{L_{32}}:
2L31=6  ⟹  L31=3L31+3L32=15  ⟹  3+3L32=15  ⟹  L32=4\displaystyle \begin{aligned} \pivot{2}\mult{L_{31}} &= 6 \;\Longrightarrow\; \mult{L_{31}} = 3 \\ \mult{L_{31}} + \pivot{3}\mult{L_{32}} &= 15 \; \\ &\Longrightarrow\; 3 + \pivot{3}\mult{L_{32}} = 15 \; \\ &\Longrightarrow\; \mult{L_{32}} = 4 \end{aligned}
(Don't divide the original entry 1515 directly by the second pivot 3\pivot{3} to get L32=153=5\mult{L_{32}} = \frac{15}{\pivot{3}} = 5 and [351]\begin{bmatrix} 3 & 5 & 1 \end{bmatrix}: subtracting 3\mult{3} times Row 1 of UU first changes the (3,2)(3,2) entry from 1515 to 15−3(1)=1215 - \mult{3}(1) = 12 before you divide by the second pivot 3\pivot{3}.)
[341]\displaystyle \begin{bmatrix} 3 & 4 & 1 \end{bmatrix}