The school method of eliminating unknowns, made systematic: forward elimination and back substitution, Gauss–Jordan and the inverse, the operation count, and partial pivoting to keep rounding errors under control.
The edges of a square plate are held at fixed temperatures. What is the temperature at the four marked interior points?
Cramer and the inverse: exact formulas, but the cost grows like .
Eliminate unknowns column by column; count the cost; add pivoting for safety.
input A (n×n), b
for k = 1 … n−1: # forward
if a[k][k] = 0: stop (pivot)
for i = k+1 … n:
m ← a[i][k] / a[k][k]
for j = k … n:
a[i][j] ← a[i][j] − m·a[k][j]
b[i] ← b[i] − m·b[k]
for i = n … 1: # backward
s ← b[i] − Σ_{j>i} a[i][j]·x[j]
x[i] ← s / a[i][i]Three nested loops in the forward part: that is where the comes from.
Eliminate above and below each pivot and scale it to 1. The left part becomes and the right part is the answer.
input M = [A | B] # B = b or I
for k = 1 … n:
if m[k][k] = 0: stop (pivot)
R_k ← R_k / m[k][k]
for i = 1 … n, i ≠ k:
R_i ← R_i − m[i][k]·R_k
return right part of MAbout operations: 50% more than Gaussian elimination, because it also clears the entries above the pivots.
| Gauss: operations | time | matrix memory | |
|---|---|---|---|
| 3 | 28 | 28 ns | 72 B |
| 100 | 0.7 ms | 80 KB | |
| 1000 | 0.67 s | 8 MB | |
| 10 000 | 11 min | 800 MB |
Cramer's rule: about operations, far beyond any computer that could ever be built. Gaussian elimination: 681 550 operations, under a millisecond.
Before eliminating column , bring the largest () into the pivot position.
for k = 1 … n−1:
p ← argmax_{i ≥ k} |a[i][k]|
if a[p][k] = 0: stop (singular)
swap rows k and p of [A | b]
for i = k+1 … n:
m ← a[i][k] / a[k][k] # |m| ≤ 1
R_i ← R_i − m·R_kMultipliers at most 1 in size keep rounding errors from growing. It costs only comparisons, no extra arithmetic.
| Without pivoting | With partial pivoting | |
|---|---|---|
| pivot row | swap: first | |
| multiplier | ||
| new row 2 | ||
| 1.00 | 1.00 | |
| error in | 100% | 0.01% |
With pivoting, and : the rounding only touches digits that do not matter.
Rule of thumb: for one dense system, Gaussian elimination with partial pivoting is the default; switch only when the matrix has special structure.
| Method | Operations | Stable? | Gives ? | Typical use | |
|---|---|---|---|---|---|
| Cramer (cofactors) | impossible | no | via adjugate | 2×2, 3×3 by hand | |
| Gauss, no pivoting | 0.67 s | no (tiny pivots) | no | diagonally dominant or SPD matrices | |
| Gauss, partial pivoting | + comparisons | 0.67 s | yes (in practice) | no | the default solver |
| Gauss–Jordan | 1.0 s | yes, with pivoting | yes | inverses, RREF | |
| Inverse, then | 2.0 s | less accurate | yes | avoid for solving |
Without pivoting, elimination is still safe for diagonally dominant and for symmetric positive definite matrices: the pivots can never become small. Lecture 13 uses this.
Elimination is the workhorse, but it treats every matrix as dense and every right-hand side as new.
Click a card to see elimination at work inside a real computation.
Where exactly: steady-state heat simulation. Each interior grid point gives one equation (the average of its neighbours); elimination solves them all at once.
Press All steps: . The point next to the hot top edge and the 50° right edge is warmest.
Where exactly: polynomial interpolation (Lecture 17). Requiring to pass through , , gives a 3×3 linear system.
Solution , , : . Lecture 17 gives formulas that avoid solving this system.
Where exactly: stoichiometry. For , each element gives one equation; set and solve.
The system has a free variable (any multiple of a balanced equation is balanced): Gauss–Jordan reveals that directly.
Where exactly: NumPy, MATLAB and R. np.linalg.solve(A, b) calls LAPACK's dgesv, which is Gaussian elimination with partial pivoting, organised as an LU factorisation.
Today's algorithm, with Lecture 13's bookkeeping, is literally what runs.
Elimination of the plate system gives , , , in 62 operations. A 100 × 100 grid (10 000 unknowns) takes about 11 minutes this way: Lecture 14 does better.
LU, Cholesky and tridiagonal systems. Keep the multipliers and solve for many right-hand sides cheaply; exploit symmetry and sparsity.