Elimination done once and reused: LU factorisation (Doolittle and Crout) for many right-hand sides, Cholesky for symmetric positive definite matrices at half the cost, and the Thomas algorithm that solves tridiagonal systems in linear time.
The top edge of the plate from Lecture 12 is heated and cooled during the day. The matrix never changes; only the right-hand side does.
| top edge | ||||
|---|---|---|---|---|
| 100° | 43.75 | 56.25 | 18.75 | 31.25 |
| 80° | ? | ? | ? | ? |
| 60° | ? | ? | ? | ? |
Gaussian elimination with partial pivoting: for each system.
Factor once, solve many times; exploit symmetry and zeros.
Doolittle: has ones on its diagonal. Compute row of , then column of , for .
for i = 1 … n: # factor once
for j = i … n:
u[i][j] ← a[i][j] − Σ_{k<i} l[i][k]·u[k][j]
l[i][i] ← 1
for j = i+1 … n:
l[j][i] ← (a[j][i] − Σ_{k<i} l[j][k]·u[k][i]) / u[i][i]
for each right-hand side b: # solve often
y ← forward(L, b)
x ← backward(U, y)Same operations as elimination, organised so that each entry of and is computed once.
Both cost the same and solve the same way. Crout's is Doolittle's with each column multiplied by the pivot; Crout's is Doolittle's with each row divided by it. A problem that names a method expects that placement of the ones.
for j = 1 … n:
s ← a[j][j] − Σ_{k<j} l[j][k]²
if s ≤ 0: stop (not SPD)
l[j][j] ← √s
for i = j+1 … n:
l[i][j] ← (a[i][j] − Σ_{k<j} l[i][k]·l[j][k]) / l[j][j]
y ← forward(L, b)
x ← backward(Lᵀ, y)square roots, about other operations.
input a, b, c, d (length n)
c′[1] ← c[1]/b[1]; d′[1] ← d[1]/b[1]
for i = 2 … n: # down
w ← b[i] − a[i]·c′[i−1]
if w = 0: stop
c′[i] ← c[i]/w
d′[i] ← (d[i] − a[i]·d′[i−1])/w
x[n] ← d′[n]
for i = n−1 … 1: # up
x[i] ← d′[i] − c′[i]·x[i+1]Two loops, no nested loop: the work grows like .
| 1 | — | 2 | −1 | 100 | 2 | −0.5 | 50 | 80 |
| 2 | −1 | 2 | −1 | 0 | 1.5 | −0.666667 | 33.333333 | 60 |
| 3 | −1 | 2 | −1 | 0 | 1.333333 | −0.75 | 25 | 40 |
| 4 | −1 | 2 | — | 0 | 1.25 | — | 20 | 20 |
Down sweep fills and ; up sweep: , , , . A straight line from 100° to 0°, as physics predicts.
A full matrix of doubles needs 8 TB of memory, and dense elimination operations (21 years at per second). The Thomas algorithm: operations (8 ms) and four vectors (32 MB).
Rule of thumb: tridiagonal → Thomas; SPD → Cholesky; many right-hand sides → LU once; otherwise Gaussian elimination with pivoting.
| Method | Needs | Factor | Each new | Memory | , 1440 b's |
|---|---|---|---|---|---|
| Gauss each time | any nonsingular | — | 16 min | ||
| Inverse, then multiply | any nonsingular | 4.9 s | |||
| LU (with pivoting) | any nonsingular | 3.5 s | |||
| Cholesky | SPD | 3.2 s | |||
| Thomas | tridiagonal, diag. dominant | 7 ms (if tridiagonal) |
Times at operations per second. The inverse row is slower and less accurate than LU for the same job.
Direct factorisations are fast for dense, banded and tridiagonal matrices. Some problems are still out of reach:
Click a card to see where the factorisation happens in a real computation.
Where exactly: simulating how a rod cools over time. The implicit (backward Euler) method is stable for any time step, but each step needs a tridiagonal solve; the matrix is the same every step.
The same structure appears in option pricing (Black–Scholes, Crank–Nicolson scheme) and in diffusion in images.
Where exactly: simulation and probabilistic machine learning. To sample a random vector with covariance , factor and set , where has independent standard normal entries.
Covariance matrices are SPD, so Cholesky always applies (and is the standard choice in NumPy: np.linalg.cholesky).
Where exactly: cubic spline interpolation (Lecture 18), used in fonts, CAD, animation paths and data smoothing. Continuity of the slope and curvature at the data points gives one equation per point, involving only its two neighbours.
This is why splines are cheap enough to use everywhere.
Where exactly: structural analysis by the finite element method. The stiffness matrix (SPD) depends only on the structure; each load case (wind, traffic, snow, earthquake) is a new right-hand side in .
Exactly the opening problem: the factorisation is paid once, every extra case is cheap.
One LU of the plate matrix, then three solves: top 100° gives ; 80° gives ; 60° gives . For and 1440 readings: 3.5 s instead of 16 minutes.
Iterative methods: Jacobi, Gauss–Seidel and SOR. When the matrix is huge and sparse, stop factoring and start iterating, just like fixed-point iteration in Lecture 8.