Contents · Linear Algebra
Part 0 · Orientation
Part 1 · Vectors & Spaces
Part 2 · Matrices as Maps
Part 3 · Solving Systems
Part 4 · Orthogonality
Part 5 · Eigenvalues
Part 6 · Singular Value Decomposition
Part 7 · Spectral & Positive Definite
Part 8 · Numerical Linear Algebra
- Numerical Linear Algebra: Conditioning, Stability, and Iteration
Part 8 · Numerical Linear Algebra
Numerical Linear Algebra: Conditioning, Stability, and Iteration
On paper, a matrix is invertible or it is not. On a computer working in finite precision, that binary is the wrong question. Every number carries a rounding error near , and the right-hand side of a physical solve is itself measured or approximated. The question becomes: how much does the answer move when the data moves a little? One number answers it.
The condition number
The singular value decomposition writes with . Geometrically maps the unit sphere to an ellipsoid whose semi-axis lengths are the . The condition number is the axis ratio,
It bounds error amplification exactly. Let and perturb the right-hand side to , giving . Then , so and , while . Multiplying the two,
A relative error of in the data can surface as a relative error of in the solution. When , half your digits are gone before you start; when is small the ellipse is nearly a circle and errors barely grow.1
- κ(A) = σ_max/σ_min
- 135.4
- σ_max
- 2.015
- σ_min
- 0.015
- x = A⁻¹b
- (1.00, 0.00)
- δx
- (-4.00, 4.00)
- amplification
- 66.7 ≤ κ
κ > 100: the ellipse is a near-line and a tiny δb swings x hard.
A nearly singular system, by hand
Take two almost-parallel rows,
The determinant is nonzero, so inverts, but its singular values are and , giving
Solve for . Row two minus row one gives , so and :
Now nudge only the second entry of by , a relative change of . The same elimination now reads , so
The solution moved by (). The amplification is , safely under , and the bound is nearly tight because points along the smallest singular direction. A stray bit in the fourth decimal of rewrites the answer.
Direct is too expensive: iterate
A dense factorization solves in . The systems in a physics simulation are large and sparse, often unknowns with a handful of nonzeros per row, so is out of reach and factorization would destroy the sparsity anyway. Split into its diagonal, strictly lower, and strictly upper parts, and iterate.
Jacobi updates every component from the previous sweep; Gauss-Seidel reuses each freshly computed value at once:
Each is for an iteration matrix (, ). The error obeys , so the method converges for every starting guess if and only if the spectral radius , and the smaller the faster.2 For a symmetric positive-definite , conjugate gradient does far better: its error in the -norm shrinks by per step, so it reaches a fixed tolerance in about iterations rather than . Conditioning sets the iteration count directly.
The numerical backbone
This is the machinery under a contact solver. The velocity-level contact system has , the Delassus operator, which is symmetric positive semidefinite: exactly the shape conjugate gradient and its projected variants want. Projected Gauss-Seidel, the sequential-impulse method of Box2D and Bullet, is the Gauss-Seidel split above with a clamp after each component. Its convergence rate is , and grows as the contacts couple more tightly, so a tall stack or a large mass ratio drives up and the solver needs more sweeps. The condition number is not an abstraction here; it is the number of iterations per frame.