Worked examples — LU decomposition — algorithm, applications
The scenario matrix
Every you can be asked to factor falls into one of these cells. We will hit all of them.
| # | Cell (the scenario) | What makes it special | Example |
|---|---|---|---|
| C1 | Generic , all pivots nonzero | The "textbook happy path" | Ex 1 |
| C2 | Generic , then solve | Combine factor + two solves | Ex 2 |
| C3 | Zero pivot in the top-left — needs a row swap | Naive fails | Ex 3 |
| C4 | Tiny pivot — mathematically fine but numerically dangerous | Why we pivot for stability | Ex 4 |
| C5 | Singular matrix () — a pivot dies to zero after elimination | LU still exists, has a zero on the diagonal | Ex 5 |
| C6 | Use LU to get and | Reuse the same | Ex 6 |
| C7 | Many right-hand sides at once (real-world word problem) | The 80/20 payoff | Ex 7 |
| C8 | Negative & fractional entries — sign bookkeeping in multipliers | Signs of | Ex 8 |
| C9 | Non-square (rectangular) matrix | LU still works column-by-column; square, rectangular | Ex 9 |
Each example below is tagged with its cell.
Notation we will actually use (built from zero)
Before any arithmetic, let us name every symbol so nothing appears unearned.
Figure s01 (in words). A grid of cells labelled (top row) and (bottom row). The top-left cell is highlighted amber and labelled "PIVOT (divide by this)". The bottom-left cell is highlighted cyan and labelled "kill this to 0". To the right, the formula is written with the caption "how many pivot-rows to subtract." So: amber = the number you divide by, cyan = the number you're trying to zero out, and their ratio is the multiplier.

C1 — the happy path
Forecast: guess — will have a whole number or a fraction under its diagonal? (The pivot is , the number below is , so predict .)
- Pivot ; multiplier . Why this step? We must kill the under the pivot; is exactly how many pivot-rows to subtract.
- RowRowRow: . Why? Subtracting of leaves — the first entry becomes as designed.
- Assemble: , . Why? is what survived; stores the .
Verify: ✓
C2 — factor then solve
Forecast: the entries double each time — expect clean whole multipliers .
- Column 1. , . RowRow; RowRow. Why? Clear everything below the first pivot using ratios to it.
- Column 2. New pivot (position ). . Row. Why? Now clear below the second pivot; we always use the current pivot row.
- Assemble.
- Forward solve : Why forward? is lower triangular, so the top row is solved instantly and each new row uses only known values.
- Back solve : Why back? is upper triangular, so the bottom variable is isolated first.
Verify: ✓
C3 — zero pivot, must permute ()
Forecast: the top-left entry is . Can you compute ? No — dividing by zero is undefined. So naive cannot start. We must swap rows first.
Figure s02 (in words). Two matrices side by side. On the left, the matrix with its top-left entry () highlighted amber and labelled "cannot divide by 0" — this is the fatal zero pivot. A cyan arrow labelled "swap rows, " points to the right, where the swapped matrix appears with its top-left entry () highlighted green and labelled "pivot = 3 (good)". Message: swapping rows turns a dead zero pivot into a live nonzero one.

- Diagnose the failure. Pivot ; is impossible. Why? Elimination requires dividing by the pivot. A zero pivot has no valid multiplier. (This is the amber cell in the figure.)
- Swap rows 1 and 2. Record the swap in a permutation matrix , giving Why? just re-orders rows; multiplying on the left by physically performs the swap and keeps a permanent receipt. (This is the cyan arrow in the figure.)
- Now factor . It is already upper triangular. The only entry below a pivot is the entry, which is already , so — no elimination is required at all. Why does become the identity? stores the multipliers, and here every multiplier is because there was nothing to subtract — the entries below each pivot were already zero. A grid of 's on the diagonal and 's below it is the identity, so .
Verify: And unwinding: recovers the original. ✓ (Check: .)
C4 — tiny pivot, stability twist
Forecast: the pivot is not zero, so naive LU works mathematically. But is huge — guess that this large number is where rounding error would hide.
- Naive (no swap). . RowRow: . Why note the size? On a computer that rounds, could swallow the true ; the multiplier amplifies any error. Mathematically exact, numerically fragile.
- With partial pivoting. Swap so the entry of largest absolute value in the column () becomes the pivot: , RowRow. Why better? Now every multiplier has magnitude , so no error gets amplified.
Verify: naive ✓; pivoted ✓.
C5 — singular matrix,
Forecast: rows and look proportional-ish; . Predict a zero pivot appears and .
- Column 1. . RowRow; RowRow. Why? Standard clearing under the first pivot .
- Column 2. The candidate pivot is now , and every entry below it is also . There is nothing to eliminate. Formally — undefined, but since is already no elimination is needed, so we set and move on. Why ? A multiplier tells us how many pivot-rows to subtract to zero out the entry below; that entry is already zero, so we subtract nothing, i.e. the multiplier is . No swap can help because the whole subcolumn is zero — the mark of a singular matrix.
- Assemble. Note the pivot pattern is broken: a zero sits on the diagonal at .
- Determinant. Why? A single zero pivot on the diagonal of makes the product zero — the matrix is singular, no inverse.
Verify: ✓ and ✓ (rows are linearly dependent: Row-Row = Row).
C6 — determinant AND inverse from one factorisation
Forecast: pivots were ; predict .
- Determinant Why? ; has all- diagonal so contributes .
- Set up the inverse by columns. Recall (definition above) are the columns of . The -th column of is the solution of , solved with the same from Ex 2 (see Matrix Inverse). Why reuse? Factorisation was the expensive part; each column is just two cheap triangular solves, forward then back.
- Column 1 — solve . Forward : Back : So column 1 of is . Why? This single column shows the full recipe; columns 2 and 3 repeat it with .
- Column 2 — solve the same way. Forward : Back : So column 2 is . Column 3 — solve . Forward : Back : So column 3 is . Why identical process? never change — only the right-hand side does, which is the whole point of LU.
- Assemble the inverse by placing each solved column side by side: Why trust it? is checked in VERIFY.
Verify: ✓, and ✓ (both machine-checked below).
C7 — real-world word problem, many right-hand sides
Forecast: is already upper triangular — guess and both solves are pure back-substitution.
- Factor once. has all zeros below the diagonal, so no elimination is needed: , . Why once? Same both days — factor a single time, reuse for every .
- Monday, forward solve . Since , we get immediately. Why trivial? The identity leaves any vector unchanged.
- Monday, back solve : ; ; . Why bottom-up? isolates the last variable first. Monday batches: .
- Tuesday, forward solve . Again , so . Why no re-factor? We reuse the exact same — only the right-hand side changed.
- Tuesday, back solve : ; ; . Tuesday batches: .
Verify (units: batches): Monday ✓; Tuesday ✓. Each new day cost only work (one forward + one back solve), not a fresh elimination.
C8 — negative & fractional entries (sign bookkeeping)
Forecast: pivot is negative. The multiplier is negative too — guess carries a negative number below its diagonal, and subtracting a negative multiple = adding.
- Multiplier. Why the sign? The formula doesn't care about signs — it always answers "how many pivot rows to subtract." Here it's .
- Eliminate. RowRow RowRow: Why "+"? Subtracting a negative multiplier flips to addition — the algebra self-corrects.
- Assemble. , .
Verify: ✓. Also , matching ✓.
C9 — non-square (rectangular) matrix
Forecast: has more rows than columns. Guess: stays square (, one row per row of ) while inherits the rectangular shape (). The idea is unchanged — clear each column below its pivot.
- Column 1. Pivot ; , . RowRow; RowRow. Why? Same rule: subtract pivot-rows to zero the first column below the pivot.
- Column 2. New pivot at position ; . RowRow. Why? We only have two columns, so this is the last pivot; clear what remains below it.
- Assemble. is (stores the three multipliers), is (the surviving grid): Why the bottom-zero row of ? With only two columns, the third row has no pivot left — it becomes an all-zero row, which is normal for a "tall" matrix.
Verify: ✓ (machine-checked below).
Recall Which cell would each stump you?
Zero top-left entry — which cell and what fix? ::: C3; swap rows, record in , factor . Pivot equals but nonzero — is LU wrong? ::: C4; it's mathematically fine but numerically unstable, so pivot to the largest-magnitude entry. A whole subcolumn below the pivot is zero — swap? ::: C5; no valid nonzero entry to swap in — matrix is singular, . Two different 's, same — recompute ? ::: C7; no — factor once, reuse for each right-hand side at . A matrix — what shapes are ? ::: C9; stays square (), inherits the rectangular shape ().
Decision map
Connections
- LU decomposition — algorithm, applications — the parent this page drills into.
- Gaussian Elimination — every example is elimination with the steps saved.
- Permutation Matrices — the row-swap receipts in C3, C4.
- Determinants — read off pivots in C5, C6, C8.
- Matrix Inverse — column-by-column reuse in C6.
- Triangular Systems & Substitution — the cheap forward/back solves everywhere.
- Cholesky Decomposition — the symmetric positive-definite cousin.