Hyoungseo Son
Linear Algebra
Contents · Linear Algebra

Part 1 · Vectors & Spaces

Part 4 · Orthogonality

Part 5 · Eigenvalues

Part 6 · Singular Value Decomposition

Part 8 · Numerical Linear Algebra

  • Numerical Linear Algebra: Conditioning, Stability, and Iteration

Part 8 · Numerical Linear Algebra

Numerical Linear Algebra: Conditioning, Stability, and Iteration

8 min read

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 101610^{-16}, 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 A=UΣVA = U\Sigma V^{\top} with Σ=diag(σ1σn0)\Sigma = \operatorname{diag}(\sigma_1 \ge \dots \ge \sigma_n \ge 0). Geometrically AA maps the unit sphere to an ellipsoid whose semi-axis lengths are the σi\sigma_i. The condition number is the axis ratio,

κ(A)=σmaxσmin1.\kappa(A) = \frac{\sigma_{\max}}{\sigma_{\min}} \ge 1.

It bounds error amplification exactly. Let Ax=bA x = b and perturb the right-hand side to b+δbb + \delta b, giving x+δxx + \delta x. Then Aδx=δbA\,\delta x = \delta b, so δx=A1δb\delta x = A^{-1}\delta b and δxσmin1δb\lVert\delta x\rVert \le \sigma_{\min}^{-1}\lVert\delta b\rVert, while b=Axσmaxx\lVert b\rVert = \lVert A x\rVert \le \sigma_{\max}\lVert x\rVert. Multiplying the two,

δxx    κ(A)δbb.\frac{\lVert\delta x\rVert}{\lVert x\rVert} \;\le\; \kappa(A)\,\frac{\lVert\delta b\rVert}{\lVert b\rVert}.

A relative error of 101610^{-16} in the data can surface as a relative error of κ1016\kappa \cdot 10^{-16} in the solution. When κ108\kappa \approx 10^{8}, half your digits are gone before you start; when κ\kappa is small the ellipse is nearly a circle and errors barely grow.1

The condition number is an axis ratiointeractive
κ(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 maps the dashed unit circle to the accent ellipse. Blue is the σ_max axis, gold the σ_min axis; κ is their ratio (red past 100). Push d toward 1 to flatten the ellipse toward a line, then move δb: the amplification (relative Δx over relative δb) climbs but never passes κ.

A nearly singular system, by hand

Take two almost-parallel rows,

A=[1111.0001],detA=0.0001.A = \begin{bmatrix} 1 & 1 \\ 1 & 1.0001 \end{bmatrix}, \qquad \det A = 0.0001.

The determinant is nonzero, so AA inverts, but its singular values are σmax2.0000\sigma_{\max} \approx 2.0000 and σmin5.0×105\sigma_{\min} \approx 5.0\times 10^{-5}, giving

κ(A)=2.00005.0×1054.0×104.\kappa(A) = \frac{2.0000}{5.0\times 10^{-5}} \approx 4.0\times 10^{4}.

Solve Ax=bA x = b for b=(2,2.0001)b = (2,\, 2.0001)^{\top}. Row two minus row one gives 0.0001x2=0.00010.0001\,x_2 = 0.0001, so x2=1x_2 = 1 and x1=1x_1 = 1:

x=[11].x = \begin{bmatrix} 1 \\ 1 \end{bmatrix}.

Now nudge only the second entry of bb by δb=(0,0.0001)\delta b = (0,\, 0.0001)^{\top}, a relative change of δb/b3.5×105\lVert\delta b\rVert / \lVert b\rVert \approx 3.5\times 10^{-5}. The same elimination now reads 0.0001x2=0.00020.0001\,x_2 = 0.0002, so

x=[02],δx=[11].x' = \begin{bmatrix} 0 \\ 2 \end{bmatrix}, \qquad \delta x = \begin{bmatrix} -1 \\ 1 \end{bmatrix}.

The solution moved by 100%100\% (δx/x=1\lVert\delta x\rVert / \lVert x\rVert = 1). The amplification is 1/(3.5×105)2.8×1041 / (3.5\times 10^{-5}) \approx 2.8\times 10^{4}, safely under κ\kappa, and the bound 1κ3.5×1051.411 \le \kappa \cdot 3.5\times 10^{-5} \approx 1.41 is nearly tight because δb\delta b points along the smallest singular direction. A stray bit in the fourth decimal of bb rewrites the answer.

Direct is too expensive: iterate

A dense LULU factorization solves Ax=bA x = b in O(n3)O(n^{3}). The systems in a physics simulation are large and sparse, often 10510^{5} unknowns with a handful of nonzeros per row, so n3n^{3} is out of reach and factorization would destroy the sparsity anyway. Split A=D+L+UA = D + L + U 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:

xk+1=D1 ⁣(b(L+U)xk),xk+1=(D+L)1 ⁣(bUxk).x^{k+1} = D^{-1}\!\big(b - (L+U)x^{k}\big), \qquad x^{k+1} = (D+L)^{-1}\!\big(b - U x^{k}\big).

Each is xk+1=Rxk+cx^{k+1} = R\,x^{k} + c for an iteration matrix RR (RJ=D1(L+U)R_{\mathrm J} = -D^{-1}(L+U), RGS=(D+L)1UR_{\mathrm{GS}} = -(D+L)^{-1}U). The error obeys ek+1=Reke^{k+1} = R\,e^{k}, so the method converges for every starting guess if and only if the spectral radius ρ(R)<1\rho(R) < 1, and the smaller ρ(R)\rho(R) the faster.2 For a symmetric positive-definite AA, conjugate gradient does far better: its error in the AA-norm shrinks by ((κ1)/(κ+1))k\big((\sqrt{\kappa}-1)/(\sqrt{\kappa}+1)\big)^{k} per step, so it reaches a fixed tolerance in about κ\sqrt{\kappa} iterations rather than κ\kappa. Conditioning sets the iteration count directly.

The numerical backbone

This is the machinery under a contact solver. The velocity-level contact system Aλ=bA\lambda = b has A=JM1JA = J M^{-1} J^{\top}, 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 λ0\lambda \ge 0 clamp after each component. Its convergence rate is ρ(R)\rho(R), and ρ\rho grows as the contacts couple more tightly, so a tall stack or a large mass ratio drives κ\kappa up and the solver needs more sweeps. The condition number is not an abstraction here; it is the number of iterations per frame.

Footnotes

  1. Trefethen & Bau, Numerical Linear Algebra (1997).

  2. Golub & Van Loan, Matrix Computations (4th ed., 2013).