Lite / Independent Engineering Research / Week 2
Gaussian elimination, back substitution and LU
Elimination throws away its multipliers. Keep them, and you can re-solve for a new right-hand side almost for free. How?
Why should I care?
Every serious linear solver is elimination underneath. Factorising A = LU once and then solving many right-hand sides is how simulators handle a fixed circuit with changing sources, or a structure under many load cases.
- Carry out forward elimination and back substitution on a 3×3 system.
- Record the multipliers as L and the result as U, and check A = LU.
- Explain why partial pivoting is used, with the tiny-pivot example.
Predict
Solve 0.0001x₁ + x₂ = 1, x₁ + x₂ = 2 rounding every result to 3 significant figures, using the first row as pivot. What does x₁ come out as?
- About 1
- 0
- About 10,000
Guess first, then reveal
The multiplier is 10,000; at 3 significant figures 1 − 10,000 and 2 − 10,000 both round to −10,000, so x₂ = 1 and then x₁ = (1 − 1)/0.0001 = 0. Swapping rows first (partial pivoting) gives x₁ ≈ 1, x₂ ≈ 1, close to the truth.
Discover
Choose '2×2, tiny pivot' with 3-significant-figure rounding, step to the end and read x. Now turn on partial pivoting and repeat. Then step through '3×3, unique' and write down every multiplier ℓᵢⱼ.
What the interactive shows (text version)
The stepper lists each row operation in text, such as 'R2 ← R2 − (−1.5)·R1 (multiplier ℓ21 = −1.5)', and shows the matrix as a table. Options toggle partial pivoting and rounding to 3 significant figures; the readout reports the final solution.
Watch (optional)
Watch for: Gilbert Strang writes each elimination step as multiplication by an elimination matrix. Watch how those combine into L.
Gilbert Strang works through Gaussian elimination at the board, including pivots, failure cases and elimination as matrix multiplication.
“2. Elimination with Matrices.” by MIT OpenCourseWare (opens YouTube; streaming video uses a lot of data)
The video is optional. Everything you need is in this lesson's text.
Understand
Forward elimination and back substitution
Use the pivot in row 1 to make zeros below it in column 1, then the pivot in row 2 for column 2, and so on, until the matrix is upper triangular U. Then the last equation has one unknown; solve it and substitute upwards. Apply every row operation to b as well (that is why we work with [A | b]).
Keep the multipliers
The multiplier ℓᵢⱼ = (entry being cleared)/(pivot). Store it in L at position (i, j), with 1s on L's diagonal. For A = [[2, 1, −1], [−3, −1, 2], [−2, 1, 2]] the multipliers are ℓ₂₁ = −1.5, ℓ₃₁ = −1, ℓ₃₂ = 4, giving U = [[2, 1, −1], [0, 0.5, 0.5], [0, 0, −1]].
Why pivot?
Dividing by a tiny pivot creates huge multipliers, and huge numbers swamp small ones when rounded. Partial pivoting swaps up the row with the largest entry in the current column, keeping every |ℓᵢⱼ| ≤ 1. It costs almost nothing and is used by essentially every dense solver.
Explain it another way
Intuitive
Elimination tidies equations into a staircase you can walk down from the bottom. LU is writing down the tidying moves so you can repeat them on new data without thinking again.
Technical
Gaussian elimination with partial pivoting computes PA = LU. It is backward stable in practice: the computed solution solves a nearby problem (A + δA)x = b with small δA.
Mathematical
LU without pivoting exists if and only if every leading principal minor of A is non-zero.
Applied
A structural code factorises the stiffness matrix K = LU once, then solves for displacements under dozens of load cases (wind, snow, traffic) with cheap triangular solves.
Derivation: Elimination is A = LU
Subtracting ℓ₂₁ × row 1 from row 2 is left-multiplication by E₂₁ = I − ℓ₂₁e₂e₁ᵀ (the identity with −ℓ₂₁ in position (2, 1)).
Forward elimination is a product of such matrices: E₃₂E₃₁E₂₁·A = U, upper triangular.
Each Eᵢⱼ is undone by flipping the sign of its multiplier, and the inverses multiply in reverse order without interfering: L = E₂₁⁻¹E₃₁⁻¹E₃₂⁻¹ has 1s on the diagonal and ℓᵢⱼ in position (i, j).
Therefore A = LU. To solve Ax = b, solve Ly = b by forward substitution, then Ux = y by back substitution.
Cost: factorising is about (2/3)n³ operations; each extra right-hand side is only about 2n². With row swaps, PA = LU for a permutation matrix P.
Worked example 1
Solve 2x₁ + x₂ − x₃ = 8, −3x₁ − x₂ + 2x₃ = −11, −2x₁ + x₂ + 2x₃ = −3.
R2 + 1.5R1: 0.5x₂ + 0.5x₃ = 1. R3 + R1: 2x₂ + x₃ = 5. R3 − 4R2: −x₃ = 1, so x₃ = −1. Then 0.5x₂ − 0.5 = 1 gives x₂ = 3; 2x₁ + 3 + 1 = 8 gives x₁ = 2. x = (2, 3, −1).
Common mix-ups
To solve Ax = b on a computer, compute A⁻¹ and multiply.
✓ Factorise and use triangular solves: cheaper and more accurate.Row swaps change the solution.
✓ Swapping equations does not change which x satisfies them.
Practice
Practice, not a test. Answers are checked on our server; a wrong answer gets a hint and another try. Nothing is saved.
Apply it
In the Code Lab, implement lu(A) without pivoting, test that L·U reproduces A on three matrices, then show it failing on [[0, 1], [1, 0]] and explain why pivoting fixes it.
Reflect
Which rounding surprise in the tiny-pivot example would you have missed if you had used exact arithmetic?
Write your answer on paper or in your own notes. Lite never stores what you write.