Linear Algebra, Live
Strang §2.6 · Elimination = factorization

LU decomposition: A = LU keeps a record of elimination

Slide 5 wrote elimination as E₃₂E₃₁E₂₁A = U, and slide 6 showed how such products work. Now we run it backwards. Keep every multiplier ℓ from elimination in a lower triangular matrix L: 1s on the diagonal, the multipliers below it, zeros above. Then L times U gives A back: A = LU. Think of meal prep. Chop the week's vegetables on Sunday, and every dinner is quick. Factoring A = LU is the Sunday work, and each new right side b is a quick dinner: two easy triangle solves.

Lesson 2 · slide 7A = LU
A = LU    L = 100ℓ₂₁10ℓ₃₁ℓ₃₂1
Key ideas
  1. A = LU: L is lower triangular with 1s on its diagonal, U is upper triangular.
  2. The multipliers ℓᵢⱼ go straight into L, in the positions where they were used.
  3. To solve Ax = b: first solve Lc = b, then Ux = c. Both are fast triangular solves.
  4. Factor once, then reuse L and U for every new right-hand side b.

Solving with L and U

Why two solves? Replace A by LU: (LU)x = b, and the brackets can move (slide 6): L(Ux) = b. Call Ux = c. Solve Lc = b for c, then Ux = c for x.

Lc = b  (forward substitution, top to bottom)    then    Ux = c  (back substitution, bottom to top)

This is slide 3's c: b after elimination. Solving Lc = b top-down (forward substitution) just redoes those subtractions on b. Row 2 of L reads ℓ₂₁c₁ + c₂ = b₂, so with b = 5−29 from slide 3, c₂ = b₂ − ℓ₂₁c₁ = −2 − 2·5 = −12, as on slide 3. The example “Solve Lc = b by forward substitution” below finishes c₃.

Where L comes from

Slide 5 wrote elimination as E₃₂E₃₁E₂₁A = U. To get A back, undo the steps in reverse order, on both sides. To undo E₃₂, multiply both sides on the left by E₃₂⁻¹. Since E₃₂⁻¹E₃₂ = I, E₃₂ cancels. Then the same for E₃₁, then E₂₁:

E₃₂ E₃₁ E₂₁ A = U
undo E₃₂:   E₃₁ E₂₁ A = E₃₂⁻¹ U
undo E₃₁:   E₂₁ A = E₃₁⁻¹ E₃₂⁻¹ U
undo E₂₁:   A = E₂₁⁻¹ E₃₁⁻¹ E₃₂⁻¹ U = LU

Shoes come off before socks: the last step done is the first undone. So E₃₂⁻¹ sits next to U.

Each inverse is the identity with +ℓ where E had −ℓ (slide 5). In this order the multipliers don't mix: no new entries appear, and each multiplier just sits in its own spot, as the product below shows. So L needs no extra arithmetic: it is the record of the multipliers.

The example from slides 3 to 5

The multipliers were ℓ₂₁ = 2, ℓ₃₁ = −1, ℓ₃₂ = −1. Multiply the three inverses:
E₂₁⁻¹ E₃₁⁻¹ E₃₂⁻¹ = 100210001 100010−101 1000100−11 = 100210−1−11
Each multiplier sits in place: ℓ₂₁ in row 2, column 1, ℓ₃₁ in row 3, column 1, ℓ₃₂ in row 3, column 2.
So L is just the multipliers, and that is why we record L.
L = 100210−1−11   U = 2110−8−2001
Check row 3 of LU: −1·211 − 1·0−8−2 + 1·001 = −272, which is row 3 of A ✓

You can watch both triangles grow at the same time. Start with L = I and U = A. Each elimination step changes one row of U, and its multiplier drops into the same spot of L.

Left of the bar is L, right of the bar is U (here the bar only separates the two). Each step changes one row of U, and its multiplier lands in the same spot of L.

Why it saves time

For n unknowns, factoring takes about n³/3 multiplications, and both triangular solves together about n². With n = 1000: roughly 330 million operations to factor, then about a million per new b.

So when only the right side changes, as in a simulation stepping through time, factor once and reuse L and U. In the lab, lu(A) returns both factors so you can check your work.

A bigger example: 4 × 4

A = 2100231002310023
ℓ₂₁ = 2 ÷ 2 = 1: row 2 → 0210.   ℓ₃₂ = 2 ÷ 2 = 1: row 3 → 0021.   ℓ₄₃ = 2 ÷ 2 = 1: row 4 → 0002
The other multipliers (ℓ₃₁, ℓ₄₁, ℓ₄₂) are 0, because those entries are already 0
L = 1000110001100011   U = 2100021000210002
Check row 3 of LU: 1·0210 + 1·0021 = 0231 ✓

Each row of A only touches its neighbours, so L and U stay just as thin. Matrices like this come up in simulations with thousands of unknowns, and the thin L and U make every new solve very fast.

Next: The recap puts the whole lesson on one page.

Examples

Example 1 · Factor, then solve

A = 1238, b = 519.

Show solutionHide solution
ℓ = 3: U = 1202, L = 1031
Lc = b: c₁ = 5, c₂ = 19 − 15 = 4
Ux = c: 2x₂ = 4, x₂ = 2; x₁ + 4 = 5, x₁ = 1

Example 2 · A 3 by 3 factorization

A = 111122123 (from slide 3's example “A full 3 by 3 solve”).

Show solutionHide solution
L = 100110111   U = 111011001

Each multiplier was 1, so L has 1s everywhere below the diagonal.

Example 3 · A fractional multiplier

A = 4363.

Show solutionHide solution
ℓ = 6 ÷ 4 = 1.5: U = 430−1.5, L = 101.51
Check row 2 of LU: 1.5·43 + 0−1.5 = 63 ✓

Example 4

Solve Lc = b by forward substitution: L = 100210−1−11, b = 5−29.

Show solutionHide solution

c₁ = 5. Then 2·5 + c₂ = −2, so c₂ = −12. Then −5 + 12 + c₃ = 9, so c₃ = 2. c = 5−122, the same c as on slide 3.

Example 5

Why does A = 0111 have no LU factorization? How is it fixed?

Show solutionHide solution

The first pivot is 0, so no multiplier can be formed. Swap the rows first. Lesson 3 writes this swap as a matrix P: P is I with its rows swapped, and it does the row exchange first. Here PA = 1101 is already upper triangular, so PA = LU with L = I.

Exercise Fill in the missing multiplier ℓ₃₂ in L so that L @ U gives back A. Edit the code and press Run.
slide_7.py Loading Python…
1
Output · Ctrl+Enter runs
Press Run to execute this slide's code. Ctrl+Enter works too.

Enjoying lesson 2? Get the full course: all 8 lessons through the SVD and PCA, your progress saved lesson by lesson, every solution and 5 extra problems per lesson. $20 once, yours for life.

Questions and comments

Stuck on something, or found a mistake? Ask here and I'll answer. You sign in with GitHub.

The full course

From Ax = b to PCA, by running it

Lessons 1 to 3 are free. Finish all eight and you will be able to:

You get: all 8 lessons with Python labs · every worked example and solution · 5 extra problems per lesson · your progress tracked · answers to your questions · every future update.

$20 once · lifetime access
Continue to checkout →

Already a member? Log in to the course