Skip to content
Tactiverge

School/✦ Research Engineer/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?

About 50 min · 3 goals · Checked by automated tests

1.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.

2.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 ℓᵢⱼ.

Loading the interactive…

Can't use the interactive? Read a description instead

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.

3.Checkpoint: guided practice

Check what you just discovered before going on. Hints appear after a wrong answer.

Practice 1

In A = [[2, 1, −1], [−3, −1, 2], [−2, 1, 2]], what multiplier ℓ₂₁ clears the (2, 1) entry?

Practice 2 · a fresh version every time

Solve A·x = b with A = [[-2, 3, -2], [-2, 3, 4], [-3, 4, -3]] and b = (-11, 7, -15). What is x3?

4.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?

Guess first. Being wrong here is how the surprise works.

5.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

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.

Derivation: Elimination is A = LU
  1. Subtracting ℓ₂₁ × row 1 from row 2 is left-multiplication by E₂₁ = I − ℓ₂₁e₂e₁ᵀ (the identity with −ℓ₂₁ in position (2, 1)).

  2. Forward elimination is a product of such matrices: E₃₂E₃₁E₂₁·A = U, upper triangular.

  3. 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).

  4. Therefore A = LU. To solve Ax = b, solve Ly = b by forward substitution, then Ux = y by back substitution.

  5. 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.

6.Watch

→ 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.

Length: see YouTube · captions on YouTube · source

Nothing loads from YouTube until you press play.

The video is optional: everything you need is also in the lesson text and the interactive.

7.Practice on your own

Practice, not a test. Wrong answers get a hint and another try.

Practice 3

Why does partial pivoting help?

Practice 4

You have A = LU. A new right-hand side b′ arrives. What do you do?

Practice 5

Factorising costs about (2/3)n³ operations. Roughly how many times longer does n = 2000 take than n = 1000?

8.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.

9.Reflect

Concepts: Linear systems, elimination and rank · Numerical linear algebra: conditioning, LU and power iteration