Worked examples — LU decomposition (numerical)
Before anything, the vocabulary we reuse (all built in the parent): means we split a square number-grid into a lower-triangular (zeros above the diagonal, 1's on it) times an upper-triangular (zeros below the diagonal). We solve by first walking down (, forward substitution) then up (, back substitution). If you're shaky on any of these words, re-read Gaussian Elimination and Forward and Back Substitution first.
The scenario matrix
Every LU problem you'll meet falls into one of these cells. We will hit each one with a worked example.
| Cell | Case class | What's special | Example |
|---|---|---|---|
| C1 | Clean , nonzero pivots | The textbook happy path | Ex 1 |
| C2 | Clean | Watch the sums grow | Ex 2 |
| C3 | Zero pivot, matrix still invertible | , must pivot () | Ex 3 |
| C4 | Tiny pivot vs. big pivot | Rounding blows up without pivoting | Ex 4 |
| C5 | Multiple right-hand sides | The whole point: factor once, solve twice | Ex 5 |
| C6 | Singular matrix | A pivot becomes with nothing to swap | Ex 6 |
| C7 | Determinant via LU (with a swap) | Sign flip from the permutation | Ex 7 |
| C8 | Word problem (real world) | Set up from a story | Ex 8 |
C1 — Clean : the happy path
Forecast: guess the sign of both answers before computing. (Hint: the second equation is "heavier".)
- . Why this step? Row 1 of is , so multiplying gives the top row of = top row of untouched.
- . Why? This is the Gaussian multiplier — "what times row 1 do I subtract from row 2 to kill the ?"
- . Why? Subtract what the column-1 elimination dumped into position .
- Forward solve : ; then . Why top-first? The first row of has only one unknown.
- Back solve : ; then . Why bottom-first? The last row of has only one unknown.
Verify: ✓. And ✓.
C2 — Clean : watch the sums grow
Forecast: will all three pivots come out positive? Guess now.
- Row 1 of : . Why? Same reason as C1 — top row copies over.
- Column 1 of : , . Why? Multipliers to zero the two entries below the first pivot.
- Row 2 of : ; . Why? Subtract row-1's contribution using the Doolittle sum .
- Column 2 of : . Why? The multiplier to kill entry after column-1 was cleared.
- Row 3 of : . Why? The last pivot is what's left after both earlier columns paid their share.
Verify: multiply — row 2 gives ✓, row 3 gives ✓. Pivots are all positive, as forecast for this nice symmetric-looking matrix.
C3 — Zero pivot, but is invertible: you MUST pivot
Forecast: does LU simply fail here, or is there a rescue?
- Naive attempt: , then — division by zero. Why this step matters? It shows a perfectly invertible matrix () can still break plain Doolittle.
- Partial pivoting: swap the two rows so the biggest first-column entry () sits on the pivot. Record it in a permutation matrix . Why? Swapping rows of = multiplying by ; we now factor .
- Factor : it's already upper-triangular, so , , .
- Solve — remember to permute ! Solve , where . Forward: is identity so . Back: ; .
Verify: ✓. See Partial Pivoting for the full swapping rule.
C4 — Tiny pivot vs. big pivot: accuracy matters
Forecast: both routes reach the same exact answer. Which route survives rounding?
- No-pivot factor: , , . Why note this? The multiplier is huge — that's the danger sign.
- No-pivot solve (rounded to 3 sig figs): , . Back: ; then . Rounding to 3 figures gives , so , and then — catastrophically wrong ( should be ). Why? Subtracting a huge number swamped the small ; the true information was lost.
- With pivot: swap rows (biggest first-column entry is ). , so , . Multiplier is tiny — safe.
- Pivoted solve: . , . Back: ; . Correct.
Verify: with exact arithmetic, ✓. Moral: big pivot, small error — see Condition Number and Numerical Stability.
C5 — Multiple right-hand sides: the reason LU exists
Forecast: how much new work per right-hand side? (Answer: no factoring, just two substitutions.)
Recall .
- — forward: , . Back: ; . Why no re-factoring? didn't change, only ; the elimination steps are frozen in .
- — forward: , . Back: ; .
Verify: ✓; ✓. Two solves, zero re-factoring — that's the payoff.
C6 — Singular matrix: a pivot dies with no rescue
Forecast: the second row is exactly half the first. What should the second pivot be?
- Row 1 of : . Why? Top row copies over as always.
- . Why? Standard multiplier.
- . Why this is fatal? is the last pivot; there is no row below to swap in. Back substitution would need , unsolvable (or infinitely many).
Verify: the factorization is still valid ( ✓), but , confirming is singular. A zero pivot at the last position means no unique solution exists — pivoting cannot save you here. This is the honest signal that has no unique answer.
C7 — Determinant via LU (with a swap)
Forecast: we needed a row swap in row 1 (since ). Will that flip the sign of ?
- Swap needed: , so pivot on the largest first-column entry, which is in row 3. One swap → factor. After swapping rows 1 and 3: Why? Determinants flip sign once per row swap; we must count swaps.
- Factor . . , . ; . . . Why? Straight Doolittle sums on the pivoted matrix.
- Assemble determinant: Why the minus? One swap = one sign flip.
Verify: expand directly along the top row: ✓.
C8 — Word problem: a real setup
Forecast: both counts must be positive (you can't make negative batches) — check this at the end.
- Factor . ; ; . Why? Standard Doolittle; the numbers are the recipe grid.
- Forward : ; . Why? lower-triangular, solve top-down.
- Back : ; . Why? upper-triangular, solve bottom-up.
Verify (units!): apple L ✓; mango L ✓. Both counts positive — physically sensible.

The figure above places every cell of our scenario matrix on one map: green cells are "LU just works", yellow cells "works but pivot first", pink cells "LU tells you something is wrong or special". Keep this mental map when a new matrix lands on your desk.
Recall Answers
A zero pivot means the multiplier below it divides by ; skipping isn't allowed, you must swap in a nonzero row ::: — but only if one exists. Pivoting kept the multiplier small so finite-precision rounding didn't wipe out real digits ::: (stability, not exactness). None — and were reused; only two substitutions ran ::: (the whole point of LU). The zero was the last pivot with no row beneath to swap — the matrix is singular ::: (). One row swap contributed a factor ::: to .
Connections
- Parent: LU decomposition — the machinery these examples exercise.
- Gaussian Elimination · Forward and Back Substitution — the two engines used in every solve.
- Partial Pivoting · Permutation Matrices — the rescue in C3, C4, C7.
- Determinants — the sign-counting in C7.
- Condition Number and Numerical Stability — why C4 matters.
- Crout Decomposition · Cholesky Decomposition — sibling factorizations for other matrix shapes.