Numerical Methods

All books

M04 — Optimisation and descent

Minimising f(x)=12xTAx−bTxf(x) = \tfrac12 x^{\mathsf T} A x - b^{\mathsf T} x and solving Ax=bAx = b are the same problem. Walking downhill is the cheapest way to do either when AA is large and sparse, and the shape of the bowl decides whether the walk takes ten steps or ten thousand. This notebook derives that speed, fixes it with conjugate gradients and with curvature (Newton), and ends where the S track starts: a fit to data, and a minimum with a constraint attached.

Book pages: Optimisation, A step has a direction and a length and Saddle point in books/numerical-methods.

The question. Gradient descent and conjugate gradients both only ever multiply by AA. Why does one need hundreds of times more of those products than the other, and what number predicts it?

By the end you can:

  • show that minimising a quadratic is solving Ax=bAx = b, and read the condition number κ\kappa off the shape of its level sets
  • derive the stable window 0<t<2/λmax⁡0 \lt t \lt 2/\lambda_{\max} for a fixed step from the error rule ek+1=(I−tA)eke_{k+1} = (I - tA)e_k
  • predict and measure the speed of steepest descent, (κ−1)/(κ+1)(\kappa-1)/(\kappa+1) per step, and explain the zig-zag
  • say why conjugate gradients finish in at most nn steps, and use the (κ−1)/(κ+1)(\sqrt\kappa-1)/(\sqrt\kappa+1) bound
  • use Newton and Gauss–Newton, and say what each needs and when each slows
  • write a constrained minimum as a KKT system, and treat a stiff spring as its compliant approximation

Assumes: M01 (measuring a rate) and M03 (the condition number); eigenvalues of a symmetric matrix; the gradient and Hessian of a function of several variables.

How to use it: predict before you reveal, commit before you check, and move the controls until the equation's behaviour stops surprising you.

Predict first. Try first: steepest descent with an exact line search on an SPD quadratic with κ=100\kappa = 100, from the worst start. How many steps to cut the error by 10610^{6}?

Choose a prediction

Check answer (without scripting)

Answer: about 700. The factor per step is (κ−1)/(κ+1)=99/101(\kappa-1)/(\kappa+1) = 99/101, so ln⁡106/ln⁡(101/99)≈690\ln 10^6 / \ln(101/99) \approx 690 steps. A line search does not rescue a narrow valley.

Warm-up: remember

1. The singular values of a Jacobian are 1.7, 1.0, 6×10−131.7,\ 1.0,\ 6 \times 10^{-13}. otkd counts those above 10−10σ110^{-10}\sigma_1. What does it report?

Question 1
How sure?

2. Why is the secant method's order about 1.618 rather than Newton's 2?

Question 2
How sure?

3. Why solve Ax=bAx = b with LU rather than form A−1A^{-1} and multiply?

Question 3
How sure?

Show answers and explanations

1. Rank 2: one rule is numerically a combination of the others. The smallest singular value is below 10−10σ110^{-10}\sigma_1, so it counts as zero. The left singular vector for it names the rows in the dependence.

2. Its new error is proportional to the product of the last two errors. ek+1≈Cekek−1e_{k+1} \approx C e_k e_{k-1}. Trying ek+1∼ekpe_{k+1} \sim e_k^p gives p=1+1/pp = 1 + 1/p, so p=(1+5)/2p = (1 + \sqrt5)/2.

3. The inverse is not backward stable for x, and costs about three times as much. x^=fl(A−1)b\hat x = \mathrm{fl}(A^{-1})b can have a backward error near κϵ\kappa\epsilon; LU's stays near ϵ\epsilon. Inversion also costs about n3n^3 against n3/3n^3/3.

1. A minimum is a linear solve

Setting: the problem, its sets and its symbols

Problem. Given a symmetric positive definite A∈Rn×nA \in \mathbb{R}^{n \times n} and b∈Rnb \in \mathbb{R}^{n}, find x∗=arg⁡min⁡x∈Rnf(x)x^* = \arg\min_{x \in \mathbb{R}^{n}} f(x) for the quadratic ff below, and relate f(x)−f(x∗)f(x) - f(x^*), ∇f(x)\nabla f(x) and the shape of the level sets of ff to AA.

Symbol In Meaning
nn N\mathbb{N} the number of unknowns; the picture has n=2n = 2
AA Rn×n\mathbb{R}^{n \times n} symmetric positive definite (SPD): A=ATA = A^{\mathsf T} and vTAv>0v^{\mathsf T}Av > 0 for v≠0v \ne 0
bb Rn\mathbb{R}^{n} the data
ff Rn→R\mathbb{R}^{n} \to \mathbb{R} f(x)=12xTAx−bTxf(x) = \tfrac12 x^{\mathsf T}Ax - b^{\mathsf T}x
∇f, ∇2f\nabla f,\ \nabla^2 f Rn→Rn, Rn×n\mathbb{R}^{n} \to \mathbb{R}^{n},\ \mathbb{R}^{n \times n} the gradient map and the (constant) Hessian
x, x∗x,\ x^* Rn\mathbb{R}^{n} a point and the minimiser (the unknown)
x0x_0 R2\mathbb{R}^{2} the start in the picture, x∗+(−1.5,0.8)x^* + (-1.5, 0.8) with x∗=(1,1)x^* = (1, 1)
ee Rn\mathbb{R}^{n} the error x−x∗x - x^*
rr Rn\mathbb{R}^{n} the residual b−Axb - Ax
∥⋅∥A\lVert \cdot \rVert_A Rn→[0,∞)\mathbb{R}^{n} \to [0, \infty) the AA-norm, ∥v∥A=vTAv\lVert v \rVert_A = \sqrt{v^{\mathsf T}Av}
λi, vi\lambda_i,\ v_i (0,∞), Rn(0, \infty),\ \mathbb{R}^{n} the eigenvalues of AA and orthonormal eigenvectors, Avi=λiviAv_i = \lambda_i v_i
κ\kappa [1,∞)[1, \infty) the condition number λmax⁡/λmin⁡\lambda_{\max} / \lambda_{\min}; the slider sets it in {1,…,50}\{1, \dots, 50\}
cc (0,∞)(0, \infty) a level: the level set is {x:f(x)−f(x∗)=c}\{x : f(x) - f(x^*) = c\}
How these symbols connect

Given an SPD matrix A∈Rn×nA \in \mathbb{R}^{n \times n} and data b∈Rnb \in \mathbb{R}^{n}, the quadratic f:Rn→Rf : \mathbb{R}^{n} \to \mathbb{R} defines both a minimisation problem for x∗∈Rnx^* \in \mathbb{R}^{n} and a linear system through its gradient ∇f:Rn→Rn\nabla f : \mathbb{R}^{n} \to \mathbb{R}^{n} and constant Hessian ∇2f∈Rn×n\nabla^2 f \in \mathbb{R}^{n \times n}. Measuring any point x∈Rnx \in \mathbb{R}^{n} against x∗x^* defines the error e=x−x∗e = x - x^* and residual r=b−Axr = b - Ax, while AA itself induces the energy norm ∥⋅∥A\lVert \cdot \rVert_A and eigenpairs (λi,vi)(\lambda_i, v_i) whose extreme ratio is κ\kappa. Setting a level c>0c > 0 traces the bowl's level set around x∗x^*, which the n=2n = 2 plot draws from x0x_0 as the slider varies κ\kappa; all quantities are dimensionless.

Symbol-by-symbol notes
$A$ SPD — symmetric positive definite

Symmetry (A=ATA = A^{\mathsf T}) guarantees real eigenvalues λi\lambda_i and a complete orthonormal basis of eigenvectors viv_i. Positive definiteness (vTAv>0v^{\mathsf T}Av > 0 for every v≠0v \ne 0) guarantees every λi>0\lambda_i > 0, making AA invertible and ff strictly convex with a unique global minimiser.

$\nabla f$ and $\nabla^2 f$ — gradient and Hessian

∇f(x)∈Rn\nabla f(x) \in \mathbb{R}^{n} is the vector of first partial derivatives (∂f/∂xj)(\partial f / \partial x_j), pointing in the direction of steepest ascent of ff. ∇2f∈Rn×n\nabla^2 f \in \mathbb{R}^{n \times n} is the symmetric matrix of second partial derivatives (∂2f/∂xi∂xj)(\partial^2 f / \partial x_i \partial x_j), which is constant across Rn\mathbb{R}^{n} for a quadratic.

$e$ vs $r$ — error against residual

The error e=x−x∗e = x - x^* measures displacement from the unknown minimiser, whereas the residual r=b−Axr = b - Ax measures how far xx misses the equation Ax=bAx = b. Notice the sign: r=b−Ax=−∇f(x)r = b - Ax = -\nabla f(x), so the downhill direction −∇f(x)-\nabla f(x) equals +r+r.

$\lVert \cdot \rVert_A$ — the $A$-norm

Defined by ∥v∥A=vTAv\lVert v \rVert_A = \sqrt{v^{\mathsf T}Av} for v∈Rnv \in \mathbb{R}^{n}; positive definiteness of AA is exactly what makes this a valid norm (strictly positive for v≠0v \ne 0). It weights each eigenvector component by λi\sqrt{\lambda_i}, unlike the Euclidean 2-norm which weights every direction equally.

$\kappa$ and $c$ — condition number and level sets

Because AA is SPD, its singular values equal its eigenvalues, so κ=λmax⁡/λmin⁡\kappa = \lambda_{\max} / \lambda_{\min} is identical to M03's 2-norm condition number κ2(A)\kappa_2(A). Each c>0c > 0 selects a single contour {x∈Rn:f(x)−f(x∗)=c}\{x \in \mathbb{R}^{n} : f(x) - f(x^*) = c\} around x∗x^*.

Take AA symmetric positive definite (SPD) and f(x)=12xTAx−bTxf(x) = \tfrac12 x^{\mathsf T} A x - b^{\mathsf T} x. Its gradient and Hessian are

∇f(x)=Ax−b,∇2f=A.\nabla f(x) = Ax - b, \qquad \nabla^2 f = A .

The gradient vanishes only at x∗=A−1bx^* = A^{-1}b, and AA positive definite makes that the unique minimum. So a minimiser of ff is a linear solver, and every linear SPD solver is a minimiser. Write e=x−x∗e = x - x^* and use b=Ax∗b = Ax^*:

f(x)−f(x∗)=12eTAe=12∥e∥A2,∇f(x)=Ae=−r.f(x) - f(x^*) = \tfrac12 e^{\mathsf T} A e = \tfrac12 \|e\|_A^2, \qquad \nabla f(x) = A e = -r .

The gap to the minimum is the error in the AA-norm, and the gradient is minus the residual. A level set 12eTAe=c\tfrac12 e^{\mathsf T}Ae = c is an ellipse whose semi-axes along the eigenvectors are 2c/λi\sqrt{2c/\lambda_i}, so the ratio of its axes is λmax⁡/λmin⁡=κ\sqrt{\lambda_{\max}/\lambda_{\min}} = \sqrt\kappa: the condition number of M03 is the bowl's narrowness. Move κ\kappa and watch the steepest direction (orange) turn away from the direction to the minimum (green).

-0.8170.091511.912.82-2.14-0.57112.574.14seriessteepest descentto the minimumxy
κ\kappa axis ratio κ\sqrt\kappa angle between −∇f-\nabla f and x∗−x0x^* - x_0
10 3.16 49.0°

At κ=1\kappa = 1 the bowl is round and the gradient points at the minimum. As κ\kappa grows the gradient points across the valley, at nearly a right angle to where you want to go. Every method below is a different answer to that.

When minimising by solving $Ax = b$ breaks
  • Assumes: AA is symmetric positive definite, so the stationary point is a minimum
  • When it fails: with a negative eigenvalue the stationary point is a saddle and ff has no minimum; a descent method then runs off to −∞-\infty along that eigenvector
  • Check: a Cholesky factorisation succeeds exactly when AA is SPD; it is the cheapest test

2. Gradient descent and the step window

Setting: the problem, its sets and its symbols

Problem. Given f(x)=12xTAx−bTxf(x) = \tfrac12 x^{\mathsf T}Ax - b^{\mathsf T}x with AA SPD, a start x0x_0 and a fixed step t>0t > 0, find the set of tt for which the iterates xk+1=xk−t ∇f(xk)x_{k+1} = x_k - t\,\nabla f(x_k) converge to x∗x^* from every x0x_0, and the error factor per step as a function of tt.

Symbol In Meaning
nn N\mathbb{N} the number of unknowns; the example has n=2n = 2
A, bA,\ b Rn×n, Rn\mathbb{R}^{n \times n},\ \mathbb{R}^{n} SPD matrix and data, as in §1; the example is A=diag(10,2)A = \mathrm{diag}(10, 2), b=0b = 0, so in coordinates f(x,y)=5x2+y2f(x, y) = 5x^2 + y^2
∇f\nabla f Rn→Rn\mathbb{R}^{n} \to \mathbb{R}^{n} the gradient, ∇f(x)=Ax−b\nabla f(x) = Ax - b
tt (0,∞)(0, \infty) the fixed step length; the slider sets it in [0.01,0.25][0.01, 0.25]
kk N0\mathbb{N}_0 the iteration count
xk, x∗x_k,\ x^* Rn\mathbb{R}^{n} the kk-th iterate and the minimiser; the example starts at x0=(1,1)x_0 = (1, 1)
eke_k Rn\mathbb{R}^{n} the error xk−x∗x_k - x^*
II Rn×n\mathbb{R}^{n \times n} the identity
λi\lambda_i (0,∞)(0, \infty) the eigenvalues of AA, with λmin⁡\lambda_{\min} and λmax⁡\lambda_{\max} the extremes
viv_i Rn\mathbb{R}^{n} orthonormal eigenvectors, Avi=λiviAv_i = \lambda_i v_i: the modes of the error
How these symbols connect

Starting from x0∈Rnx_0 \in \mathbb{R}^{n} on the SPD quadratic defined by A∈Rn×nA \in \mathbb{R}^{n \times n} and b∈Rnb \in \mathbb{R}^{n}, fixed-step gradient descent applies the update xk+1=xk−t ∇f(xk)x_{k+1} = x_k - t\,\nabla f(x_k) for k∈N0k \in \mathbb{N}_0 using a single scalar step length t>0t > 0. Subtracting the minimiser x∗x^* turns that recurrence into a linear map on the errors ek=xk−x∗e_k = x_k - x^* involving II, tt, and AA. Expanding eke_k in the orthonormal eigenvectors viv_i decouples the update into scalar recurrences controlled by the eigenvalues λi∈[λmin⁡,λmax⁡]\lambda_i \in [\lambda_{\min}, \lambda_{\max}], which determines both which values of tt converge and the per-step error factor. All quantities are dimensionless.

Symbol-by-symbol notes
$t$ — fixed step length

A constant positive scalar reused at every iteration kk, independent of the current point xkx_k. Because xk+1=xk−t ∇f(xk)x_{k+1} = x_k - t\,\nabla f(x_k) adds −t ∇f(xk)-t\,\nabla f(x_k) to xkx_k, if AA carries units (such as stiffness), tt carries the reciprocal units of AA so tAtA is dimensionless.

$x_k$ vs $x, y$ — iterate vectors against coordinates

Subscripts k∈N0={0,1,2,… }k \in \mathbb{N}_0 = \{0, 1, 2, \dots\} index iterations, so xk∈Rnx_k \in \mathbb{R}^{n} is a full vector and ek=xk−x∗e_k = x_k - x^* is its error vector. In the n=2n = 2 example f(x,y)=5x2+y2f(x, y) = 5x^2 + y^2, the unsubscripted letters xx and yy denote the two scalar coordinates of a point.

$(\lambda\lt em>i, v\lt /em>i)$ — error modes

Because AA is symmetric positive definite, its eigenvectors v1,…,vnv_1, \dots, v_n form an orthonormal basis of Rn\mathbb{R}^{n} with positive eigenvalues λ1,…,λn\lambda_1, \dots, \lambda_n. Writing eke_k in this basis separates the iteration into nn independent scalar components (modes), with λmin⁡\lambda_{\min} the softest curvature and λmax⁡\lambda_{\max} the stiffest.

$I$ — identity matrix

The n×nn \times n identity in Rn×n\mathbb{R}^{n \times n}, which leaves every eigenvector viv_i unchanged (Ivi=viIv_i = v_i). It pairs with −tA-tA when rewriting the vector update ek+1=ek−tAeke_{k+1} = e_k - tAe_k as a single matrix product.

Gradient descent takes xk+1=xk−t ∇f(xk)x_{k+1} = x_k - t\,\nabla f(x_k) with a fixed step tt. Subtract the fixed point x∗=x∗−t ∇f(x∗)x^* = x^* - t\,\nabla f(x^*) and use ∇f=Ae\nabla f = Ae:

ek+1=(I−tA) ek.e_{k+1} = (I - tA)\,e_k .

The error is multiplied by the same matrix every step. Along eigenvector ii it is multiplied by 1−tλi1 - t\lambda_i, so every mode decays only if ∣1−tλi∣<1|1 - t\lambda_i| \lt 1 for all ii:

0<t<2λmax⁡.0 \lt t \lt \frac{2}{\lambda_{\max}} .

The largest curvature sets the limit. The speed is set by the worst factor, max⁡i∣1−tλi∣\max_i |1 - t\lambda_i|.

Predict first. On f=5x2+y2f = 5x^2 + y^2 (so A=diag(10,2)A = \mathrm{diag}(10, 2), window t<0.2t \lt 0.2), which fixed step converges fastest: 0.050.05, 1/61/6 or 0.190.19?

Choose a prediction

Check answer (without scripting)

Answer: 1/6, which balances the two modes. t=2/(λmin⁡+λmax⁡)=1/6t = 2/(\lambda_{\min} + \lambda_{\max}) = 1/6 makes the two factors 1−10/6=−2/31 - 10/6 = -2/3 and 1−2/6=2/31 - 2/6 = 2/3 equal in size, the smallest possible worst case.

Reveal result (lock in your prediction above first)
01530456010⁻¹¹10⁻⁸10⁻⁵10⁻²t = 0.05t = 1/6t = 0.19iteration k|e_k|

Factors per step: t=0.05t = 0.05 gives max⁡(0.5,0.9)=0.9\max(0.5, 0.9) = 0.9, t=0.19t = 0.19 gives max⁡(0.9,0.62)=0.9\max(0.9, 0.62) = 0.9, and t=1/6t = 1/6 gives 2/32/3. The worst factor is smallest when the two extreme factors are equal and opposite, t∗=2/(λmin⁡+λmax⁡)=1/6t^* = 2/(\lambda_{\min} + \lambda_{\max}) = 1/6. The 0.050.05 and 0.190.19 lines lie on top of each other (the dashed one is 0.190.19): the same rate, with the slow mode on opposite axes. Now move the step and watch the path.

-1.1-0.54800.5481.1-2.74-1.3701.372.74xy
step tt stiff mode ∣1−10t∣\lvert 1 - 10t\rvert soft mode ∣1−2t∣\lvert 1 - 2t\rvert error after 30 steps
0.050 0.500 0.900 4.24e-02

Above t=0.2t = 0.2 the stiff factor passes 1 and the xx coordinate grows while it flips sign each step.

source: solvers/ot-solve/src/kernels/gradient.rs:95-126

The browser kernel behind the book's gradient figure: one-dimensional, f=12ax2−bxf = \tfrac12 a x^2 - bx, so the window is 0<t<2/a0 \lt t \lt 2/a. The step is two lines (grad, next); it flags Unstable once ∣x∣>106|x| > 10^6.

pub fn step(a: &mut Arena<'_>) -> Status {
    let curvature = a.params()[P_A];
    let target = a.params()[P_B];
    let step = a.params()[P_STEP];
    if !curvature.is_finite() || curvature <= 0.0 || step <= 0.0 {
        return Status::BadParameter;
    }
    let iteration = a.diag()[D_ITER] as usize;
    let x = a.state()[S_X];
    let grad = curvature * x - target;
    let next = x - step * grad;
    let state = a.state_mut();
    state[S_X] = next;
    let slot = (iteration + 1).min(HISTORY - 1);
    let value = objective(curvature, target, next);
    let out = a.out_mut();
    out[O_X + slot] = next;
    out[O_F + slot] = value;
    let diag = a.diag_mut();
    diag[D_ITER] += 1.0;
    diag[D_F] = value;
    diag[D_GRAD] = curvature * next - target;
    diag[D_CONVERGED] = if (curvature * next - target).abs() < 1.0e-9 {
        1.0
    } else {
        0.0
    };
    if !next.is_finite() || next.abs() > 1.0e6 {
        return Status::Unstable;
    }
    Status::Ok
}
When a fixed step breaks
  • Assumes: a known bound on the largest curvature λmax⁡\lambda_{\max}
  • When it fails: a step above 2/λmax⁡2/\lambda_{\max} multiplies the stiffest mode by more than 1 in size each step; the run looks plausible for a while, then overflows
  • Check: watch ff: a fixed-step run whose ff ever rises on a convex problem has left the window

3. Conditioning sets the speed

Setting: the problem, its sets and its symbols

Problem. Given f(x)=12xTAx−bTxf(x) = \tfrac12 x^{\mathsf T}Ax - b^{\mathsf T}x with AA SPD of condition number κ\kappa, find the worst-case factor by which steepest descent reduces the error per step, at the best fixed step and with an exact line search, and the number of steps NN that reduces ∥e∥A\lVert e \rVert_A by a factor 1/ε1/\varepsilon.

Symbol In Meaning
A, bA,\ b Rn×n, Rn\mathbb{R}^{n \times n},\ \mathbb{R}^{n} SPD matrix and data, as in §1; the runs use A=diag(κ,1)A = \mathrm{diag}(\kappa, 1), b=0b = 0
λmin⁡, λmax⁡\lambda_{\min},\ \lambda_{\max} (0,∞)(0, \infty) the extreme eigenvalues of AA
κ\kappa [1,∞)[1, \infty) λmax⁡/λmin⁡\lambda_{\max} / \lambda_{\min}; the slider sets it in {2,…,200}\{2, \dots, 200\}
t∗t^* (0,∞)(0, \infty) the fixed step that minimises the worst factor over all modes (§2)
xk, x∗x_k,\ x^* Rn\mathbb{R}^{n} the kk-th iterate and the minimiser
eke_k Rn\mathbb{R}^{n} the error xk−x∗x_k - x^*
gkg_k Rn\mathbb{R}^{n} the gradient ∇f(xk)=Axk−b\nabla f(x_k) = Ax_k - b
tkt_k (0,∞)(0, \infty) the exact line-search step, tk=arg⁡min⁡t>0f(xk−tgk)t_k = \arg\min_{t > 0} f(x_k - t g_k)
∥⋅∥A\lVert \cdot \rVert_A Rn→[0,∞)\mathbb{R}^{n} \to [0, \infty) the AA-norm, vTAv\sqrt{v^{\mathsf T}Av}
ε\varepsilon (0,1)(0, 1) the target: stop once ∥eN∥A≤ε∥e0∥A\lVert e_N \rVert_A \le \varepsilon \lVert e_0 \rVert_A; the try-first question uses 10−610^{-6}
NN N\mathbb{N} the number of steps to reach the target
How these symbols connect

For an SPD quadratic defined by A∈Rn×nA \in \mathbb{R}^{n \times n} and b∈Rnb \in \mathbb{R}^{n}, the extreme eigenvalues λmin⁡,λmax⁡>0\lambda_{\min}, \lambda_{\max} > 0 set the condition number κ=λmax⁡/λmin⁡\kappa = \lambda_{\max} / \lambda_{\min} (varied by the slider on A=diag(κ,1)A = \mathrm{diag}(\kappa, 1)). At each iterate xk∈Rnx_k \in \mathbb{R}^{n} with gradient gk=∇f(xk)g_k = \nabla f(x_k), steepest descent moves along −gk-g_k either with the optimal fixed step t∗t^* from §2 or with a step-dependent exact line-search length tk>0t_k > 0. Measuring the error ek=xk−x∗e_k = x_k - x^* in the AA-norm ∥⋅∥A\lVert \cdot \rVert_A lets us link κ\kappa to the worst-case contraction factor per step and to the step count NN needed to meet the relative target ε∈(0,1)\varepsilon \in (0, 1); all quantities are dimensionless.

Symbol-by-symbol notes
$t^*$ vs $t_k$ — best fixed step against exact line search

t∗>0t^* > 0 is a single constant chosen once from the extreme eigenvalues of AA and held fixed for every step. tk>0t_k > 0 is recomputed at every iteration kk by minimising the one-dimensional function t↦f(xk−tgk)t \mapsto f(x_k - t g_k) along the current gradient gkg_k, requiring no advance knowledge of λmin⁡\lambda_{\min} or λmax⁡\lambda_{\max}.

$g_k$ — gradient at iterate $k$

Shorthand for ∇f(xk)=Axk−b∈Rn\nabla f(x_k) = Ax_k - b \in \mathbb{R}^{n}, which equals AekAe_k and is minus the residual rkr_k of §1. The subscript kk marks the iteration, not a vector component.

$\lVert \cdot \rVert_A$ — why the $A$-norm is measured

Because f(xk)−f(x∗)=12∥ek∥A2f(x_k) - f(x^*) = \tfrac12 \lVert e_k \rVert_A^2, reducing ∥ek∥A\lVert e_k \rVert_A is equivalent to reducing the objective value f(xk)f(x_k). Every step of exact line search decreases ff, so ∥ek∥A\lVert e_k \rVert_A decreases monotonically even when the Euclidean error ∥ek∥2\lVert e_k \rVert_2 may not.

$\varepsilon$ and $N$ — stopping target and step count

ε∈(0,1)\varepsilon \in (0, 1) is a user-chosen dimensionless reduction factor (∥eN∥A≤ε∥e0∥A\lVert e_N \rVert_A \le \varepsilon \lVert e_0 \rVert_A), not machine epsilon ϵ\epsilon from M03. N∈NN \in \mathbb{N} is the smallest iteration index at which that reduction is achieved.

At the best fixed step the worst factor is

∣1−t∗λmin⁡∣=1−2λmin⁡λmin⁡+λmax⁡=κ−1κ+1.|1 - t^*\lambda_{\min}| = 1 - \frac{2\lambda_{\min}}{\lambda_{\min} + \lambda_{\max}} = \frac{\kappa - 1}{\kappa + 1}.

So the step count to cut the error by 1/ε1/\varepsilon is about ln⁡(1/ε)/ln⁡κ+1κ−1≈κ2ln⁡(1/ε)\ln(1/\varepsilon) / \ln\frac{\kappa+1}{\kappa-1} \approx \tfrac{\kappa}{2}\ln(1/\varepsilon): linear in κ\kappa.

Exact line search. Choose tt each step to minimise f(xk−tgk)f(x_k - t g_k) along gk=∇f(xk)g_k = \nabla f(x_k). Setting the derivative in tt to zero, −gkT(A(xk−tgk)−b)=0-g_k^{\mathsf T}(A(x_k - tg_k) - b) = 0, gives

tk=gkTgkgkTAgk,gk+1Tgk=0.t_k = \frac{g_k^{\mathsf T} g_k}{g_k^{\mathsf T} A g_k}, \qquad g_{k+1}^{\mathsf T} g_k = 0 .

The second equation is the same condition read at the new point: each new gradient is perpendicular to the last step, which in a narrow bowl is a zig-zag. The Kantorovich inequality bounds the AA-norm error by the same (κ−1)/(κ+1)(\kappa-1)/(\kappa+1) per step, and the start x0∝(1/λ1,1/λ2)x_0 \propto (1/\lambda_1, 1/\lambda_2) attains it. The line search removes the need to know λmax⁡\lambda_{\max}; it does not remove the dependence on κ\kappa.

Figure 1
Reveal result (lock in your prediction above first)

Measured at κ=100\kappa = 100: 691 steps to cut the AA-norm error by 10610^6; the factor predicts 691. Conjugate gradients' factor predicts 69 (§4). Move κ\kappa to see the zig-zag and the rate.

-0.224-0.11200.1120.224-1.12-0.5600.561.12xy
01020304010⁻¹10⁰iteration kA-norm error
κ\kappa predicted factor κ−1κ+1\frac{\kappa-1}{\kappa+1} measured factor (20 steps) steps to 10−610^{-6}
20 0.9048 0.9048 139

The measured factor is M01's observed rate: the slope of log⁡\log error against kk, read over 20 steps. From the worst start it equals the bound.

When steepest descent with a line search breaks
  • Assumes: a moderate condition number, since the factor per step is (κ−1)/(κ+1)(\kappa-1)/(\kappa+1)
  • When it fails: at κ=104\kappa = 10^4 the error falls by about 2×10−42 \times 10^{-4} of itself per step; the run looks converged because ff barely changes, while the error is still large
  • Check: measure the rate as in M01: the slope of log⁡\log error per iteration against log⁡κ−1κ+1\log\frac{\kappa-1}{\kappa+1}

4. Conjugate gradients

Setting: the problem, its sets and its symbols

Problem. Given an SPD A∈Rn×nA \in \mathbb{R}^{n \times n}, b∈Rnb \in \mathbb{R}^{n} and x0x_0, find iterates xk∈x0+Kkx_k \in x_0 + \mathcal{K}_k that minimise ff over that affine space, with AA-conjugate directions pkp_k; bound the number of steps to the exact answer and the error ∥ek∥A/∥e0∥A\lVert e_k \rVert_A / \lVert e_0 \rVert_A after kk steps.

Symbol In Meaning
A, bA,\ b Rn×n, Rn\mathbb{R}^{n \times n},\ \mathbb{R}^{n} SPD matrix and data, f(x)=12xTAx−bTxf(x) = \tfrac12 x^{\mathsf T}Ax - b^{\mathsf T}x as in §1; the runs take A=TA = T and the constant load b=h21b = h^2\mathbf 1
xk, ekx_k,\ e_k Rn\mathbb{R}^{n} the kk-th iterate and its error xk−x∗x_k - x^*, from x0=0x_0 = 0 in the runs
rkr_k Rn\mathbb{R}^{n} the residual b−Axk=−∇f(xk)b - Ax_k = -\nabla f(x_k)
pkp_k Rn\mathbb{R}^{n} the search directions, AA-conjugate: piTApj=0p_i^{\mathsf T}Ap_j = 0 for i≠ji \ne j
αk, βk\alpha_k,\ \beta_k R\mathbb{R} the step length along pkp_k and the weight of pkp_k in pk+1p_{k+1}
Kk\mathcal{K}_k subspace of Rn\text{subspace of } \mathbb{R}^{n} the Krylov space span⁡{r0,Ar0,…,Ak−1r0}\operatorname{span}\{r_0, Ar_0, \dots, A^{k-1}r_0\}
PkP_k R[λ]\mathbb{R}[\lambda] a real polynomial of degree at most kk with Pk(0)=1P_k(0) = 1
mm {1,…,n}\{1, \dots, n\} the number of distinct eigenvalues of AA whose eigenvectors e0e_0 has a component along
λmin⁡, λmax⁡, κ\lambda_{\min},\ \lambda_{\max},\ \kappa (0,∞), (0,∞), [1,∞)(0, \infty),\ (0, \infty),\ [1, \infty) the extreme eigenvalues of AA and κ=λmax⁡/λmin⁡\kappa = \lambda_{\max} / \lambda_{\min}
NN {8,16,32,64}\{8, 16, 32, 64\} the number of cells, set by the menu; h=1/(N−1)h = 1/(N - 1) is the grid spacing
TT Rn×n\mathbb{R}^{n \times n} the Poisson matrix, tridiagonal with 22 on the diagonal and −1-1 beside it, n=N−2n = N - 2; SPD
τ\tau (0,1)(0, 1) the stopping tolerance ∥rk∥2/∥b∥2≤τ\lVert r_k \rVert_2 / \lVert b \rVert_2 \le \tau; the runs use τ=10−9\tau = 10^{-9}
How these symbols connect

Given an SPD matrix A∈Rn×nA \in \mathbb{R}^{n \times n}, right-hand side b∈Rnb \in \mathbb{R}^{n}, and start x0x_0, conjugate gradients updates iterates xkx_k, residuals rk=b−Axkr_k = b - Ax_k, and AA-conjugate search directions pkp_k using scalar weights αk,βk∈R\alpha_k, \beta_k \in \mathbb{R}. Each xkx_k minimises ff over the affine Krylov space x0+Kkx_0 + \mathcal{K}_k, which links the error ek=xk−x∗e_k = x_k - x^* to degree-kk polynomials Pk∈R[λ]P_k \in \mathbb{R}[\lambda] evaluated at AA, and hence to both the active-eigenvalue count mm and the condition number κ=λmax⁡/λmin⁡\kappa = \lambda_{\max} / \lambda_{\min}. The test runs apply this on the NN-cell Poisson matrix TT with n=N−2n = N - 2 unknowns and b=h21b = h^2 \mathbf 1 until the relative residual falls to τ=10−9\tau = 10^{-9}; all quantities are dimensionless.

Symbol-by-symbol notes
$p_k$ and $A$-conjugacy

Two nonzero vectors pi,pj∈Rnp_i, p_j \in \mathbb{R}^{n} are AA-conjugate (or AA-orthogonal) when piTApj=0p_i^{\mathsf T} A p_j = 0, meaning they are orthogonal in the inner product ⟨u,v⟩A=uTAv\langle u, v \rangle_A = u^{\mathsf T}Av that induces ∥⋅∥A\lVert \cdot \rVert_A. Do not confuse this with Euclidean orthogonality piTpj=0p_i^{\mathsf T} p_j = 0.

$\mathcal{K}_k$ — Krylov subspace

Kk=span⁡{r0,Ar0,…,Ak−1r0}⊆Rn\mathcal{K}_k = \operatorname{span}\{r_0, Ar_0, \dots, A^{k-1}r_0\} \subseteq \mathbb{R}^{n} grows by at most one dimension per step as kk increases. Since every vector in Kk\mathcal{K}_k is a degree-(k−1)(k-1) polynomial in AA applied to r0r_0, minimising over x0+Kkx_0 + \mathcal{K}_k restricts eke_k to the form Pk(A)e0P_k(A)e_0 with Pk(0)=1P_k(0) = 1.

$P_k \in \mathbb{R}[\lambda]$ and $m$ — polynomial space and active eigenvalues

R[λ]\mathbb{R}[\lambda] denotes the ring of real polynomials in one scalar variable λ\lambda; the constraint Pk(0)=1P_k(0) = 1 fixes the constant term so Pk(A)e0P_k(A)e_0 stays compatible with xk−x0∈Kkx_k - x_0 \in \mathcal{K}_k. The integer m∈{1,…,n}m \in \{1, \dots, n\} counts only the distinct eigenvalues of AA whose eigenvectors have a nonzero projection in e0e_0, so mm can be strictly less than nn.

$\alpha\lt em>k$ and $\beta\lt /em>k$ — step length and direction weight

αk\alpha_k scales how far xkx_k moves along pkp_k (exact line search along pkp_k), while βk\beta_k blends the previous direction pkp_k into the new residual rk+1r_{k+1} to keep pk+1p_{k+1} AA-conjugate to earlier directions. Only αk\alpha_k carries the reciprocal units of AA when AA is dimensional; βk\beta_k is always dimensionless.

$N$, $n$, $h$, and $T$ — the 1D Poisson test grid

A grid of N∈{8,16,32,64}N \in \{8, 16, 32, 64\} cells with two fixed boundary nodes leaves n=N−2n = N - 2 interior unknowns spaced by h=1/(N−1)h = 1 / (N - 1). The matrix T∈Rn×nT \in \mathbb{R}^{n \times n} has 22 on its main diagonal and −1-1 on its first off-diagonals; it is symmetric positive definite and sparse.

Steepest descent forgets: a later step can undo progress along an earlier direction. Choose instead directions that are AA-conjugate, piTApj=0p_i^{\mathsf T} A p_j = 0 for i≠ji \ne j. Then an exact line search along pkp_k leaves the error's components along earlier directions untouched, so after kk steps xkx_k minimises ff over the whole Krylov space x0+span⁡{r0,Ar0,…,Ak−1r0}x_0 + \operatorname{span}\{r_0, Ar_0, \dots, A^{k-1}r_0\}. Each new direction needs only the last one, pk+1=rk+1+βkpkp_{k+1} = r_{k+1} + \beta_k p_k with βk=rk+1Trk+1/rkTrk\beta_k = r_{k+1}^{\mathsf T}r_{k+1}/r_k^{\mathsf T}r_k, so the cost per step is one product with AA, as for steepest descent.

Minimising over a Krylov space means the error is ek=Pk(A)e0e_k = P_k(A)e_0 for the best polynomial of degree kk with Pk(0)=1P_k(0) = 1. Two consequences:

∥ek∥A∥e0∥A≤2(κ−1κ+1)k.\frac{\|e_k\|_A}{\|e_0\|_A} \le 2\left(\frac{\sqrt\kappa - 1}{\sqrt\kappa + 1}\right)^{k}.

The square root is the whole gain: κ=104\kappa = 10^4 costs steepest descent about 50005000 steps per factor ee and CG about 5050.

Predict first. CG on the book's Poisson kernel with 64 cells: 62 unknowns, κ≈1600\kappa \approx 1600, constant load. How many iterations to cut the residual by 10910^9?

Choose a prediction

Check answer (without scripting)

Answer: 31. CG finishes in as many steps as there are distinct eigenvalues present in the starting residual. A constant load is symmetric, so only the 31 symmetric sine modes appear.

Reveal result (lock in your prediction above first)
031.863.595.212710⁻¹⁶10⁻¹²10⁻⁸10⁻⁴10⁰conjugate gradientssteepest descentiteration krelative residual
cells unknowns κ\kappa modes in bb CG steps κ\sqrt\kappa bound steepest descent steps
64 62 1608 31 31 429 16776

CG stops when it has used one step per mode present in the load, here half the unknowns, long before the bound bites. Steepest descent is shown for four times as many steps and has barely started. Doubling the cells roughly quadruples κ\kappa, so steepest descent's count grows about fourfold and CG's bound about twofold: change the cells to compare.

source: solvers/ot-solve/src/kernels/cg.rs:139-157

One CG iteration in the browser kernel: one product with the Laplacian, two dot products (pTApp^{\mathsf T}Ap and rTrr^{\mathsf T}r), two vector updates, and the new direction p=r+βpp = r + \beta p. It stops at a relative residual of 10−910^{-9}.

        laplacian(&p_block[..cells], &mut ap_block[..cells], cells);
        let p_ap = dot(&p_block[..cells], &ap_block[..cells]);
        if !p_ap.is_finite() || p_ap <= 0.0 {
            return Status::Unstable;
        }
        let rs_old = dot(&r_block[..cells], &r_block[..cells]);
        let alpha = rs_old / p_ap;
        for index in 0..cells {
            u_block[index] += alpha * p_block[index];
            r_block[index] -= alpha * ap_block[index];
        }
        let rs_new = dot(&r_block[..cells], &r_block[..cells]);
        let beta = rs_new / rs_old;
        for index in 0..cells {
            p_block[index] = r_block[index] + beta * p_block[index];
        }
        let mut field = [0.0f64; CAP];
        field[..cells].copy_from_slice(&u_block[..cells]);
        (rs_new.sqrt(), rs_new.sqrt() < TOLERANCE * initial, field)
When conjugate gradients breaks
  • Assumes: AA symmetric positive definite, and enough precision that the directions stay conjugate
  • When it fails: in floating point the directions lose conjugacy, so finite termination is lost and the κ\sqrt\kappa rate is what you get; an indefinite or non-symmetric AA breaks it outright
  • Check: the residual should fall at least as fast as the κ\sqrt\kappa bound; a stall means lost conjugacy, a non-SPD matrix, or a preconditioner that is not SPD

5. Newton and Gauss–Newton

Setting: the problem, its sets and its symbols

Problem. Given a twice continuously differentiable f:Rn→Rf: \mathbb{R}^{n} \to \mathbb{R} with a local minimiser x∗x^* at which ∇2f(x∗)\nabla^2 f(x^*) is positive definite, and a start x0x_0, find x∗x^* by Newton steps Hksk=−gkH_k s_k = -g_k and measure the order of convergence. Then, for f=12∥r∥22f = \tfrac12 \lVert r \rVert_2^2 with a residual map r:Rn→Rmr: \mathbb{R}^{n} \to \mathbb{R}^{m}, m>nm > n, whose Jacobian has full column rank, find x∗x^* by Gauss–Newton steps JkTJk sk=−JkTr(xk)J_k^{\mathsf T}J_k\, s_k = -J_k^{\mathsf T}r(x_k).

Symbol In Meaning
n, mn,\ m N\mathbb{N} unknowns and residuals; the examples have n=2n = 2 and m=9m = 9
ff Rn→R\mathbb{R}^{n} \to \mathbb{R} the objective, twice continuously differentiable; Newton's example is ex+3y−0.1+ex−3y−0.1+e−x−0.1e^{x+3y-0.1} + e^{x-3y-0.1} + e^{-x-0.1} from (2,0.5)(2, 0.5), and the warning uses Rosenbrock's (1−x)2+100(y−x2)2(1 - x)^2 + 100(y - x^2)^2 from (−1.2,1)(-1.2, 1)
xk, x∗x_k,\ x^* Rn\mathbb{R}^{n} the kk-th iterate and the minimiser
gk, Hkg_k,\ H_k Rn, Rn×n\mathbb{R}^{n},\ \mathbb{R}^{n \times n} the gradient ∇f(xk)\nabla f(x_k) and the Hessian ∇2f(xk)\nabla^2 f(x_k)
sks_k Rn\mathbb{R}^{n} the step, xk+1=xk+skx_{k+1} = x_k + s_k
eke_k Rn\mathbb{R}^{n} the error xk−x∗x_k - x^*, measured in the 2-norm
pkp_k R\mathbb{R} the observed order log⁡(∥ek∥/∥ek−1∥)/log⁡(∥ek−1∥/∥ek−2∥)\log(\lVert e_k \rVert / \lVert e_{k-1} \rVert) / \log(\lVert e_{k-1} \rVert / \lVert e_{k-2} \rVert), for k≥2k \ge 2
CC (0,∞)(0, \infty) a constant, independent of kk
rr Rn→Rm\mathbb{R}^{n} \to \mathbb{R}^{m} the residuals ri(x)=modeli(x)−datair_i(x) = \text{model}_i(x) - \text{data}_i
JkJ_k Rm×n\mathbb{R}^{m \times n} the Jacobian ∂r/∂x\partial r / \partial x at xkx_k, full column rank
c, λc,\ \lambda R\mathbb{R} the fitted parameters of y=c eλty = c\,e^{\lambda t}, so x=(c,λ)x = (c, \lambda); start (1,0)(1, 0)
ti, yit_i,\ y_i [0,4], R[0, 4],\ \mathbb{R} the nine sample times, equally spaced, and the data 2e−0.5ti2e^{-0.5 t_i} plus the misfit
ss [0,5][0, 5] the size of the fixed misfit pattern added to the data, set by the slider
How these symbols connect

Given a smooth objective f:Rn→Rf : \mathbb{R}^{n} \to \mathbb{R} and a start x0∈Rnx_0 \in \mathbb{R}^{n}, Newton's method evaluates the gradient gk=∇f(xk)g_k = \nabla f(x_k) and Hessian Hk=∇2f(xk)H_k = \nabla^2 f(x_k), solves Hksk=−gkH_k s_k = -g_k for the step sk∈Rns_k \in \mathbb{R}^{n}, and tracks the error ek=xk−x∗e_k = x_k - x^* and its observed order pkp_k. When f(x)=12∥r(x)∥22f(x) = \tfrac12 \lVert r(x) \rVert_2^2 comes from a nonlinear residual map r:Rn→Rmr : \mathbb{R}^{n} \to \mathbb{R}^{m} (m>nm > n) with Jacobian Jk∈Rm×nJ_k \in \mathbb{R}^{m \times n}, Gauss–Newton replaces HkH_k with JkTJkJ_k^{\mathsf T}J_k and solves JkTJk sk=−JkTr(xk)J_k^{\mathsf T}J_k\,s_k = -J_k^{\mathsf T}r(x_k) at each step. In the exponential-fit example, the parameters x=(c,λ)x = (c, \lambda) are fitted to nine samples (ti,yi)(t_i, y_i) with misfit amplitude ss controlled by the slider; all quantities are dimensionless.

Symbol-by-symbol notes
$s_k$ vs $s$ — Newton step against misfit scale

sk∈Rns_k \in \mathbb{R}^{n} is the vector update xk+1−xkx_{k+1} - x_k computed at iteration kk. The unsubscripted scalar s∈[0,5]s \in [0, 5] is an unrelated parameter set by the Gauss–Newton slider to scale the fixed misfit pattern added to the data yiy_i.

$p_k$ — observed convergence order

Defined for k≥2k \ge 2 as log⁡(∥ek∥/∥ek−1∥)/log⁡(∥ek−1∥/∥ek−2∥)\log(\lVert e_k \rVert / \lVert e_{k-1} \rVert) / \log(\lVert e_{k-1} \rVert / \lVert e_{k-2} \rVert), estimating the exponent pp in ∥ek+1∥≈C∥ek∥p\lVert e_{k+1} \rVert \approx C \lVert e_k \rVert^p directly from three consecutive errors. Do not confuse this scalar pkp_k with the search-direction vector pkp_k of §4.

$r$ and $J_k$ — residual map and its Jacobian

r:Rn→Rmr : \mathbb{R}^{n} \to \mathbb{R}^{m} maps the nn model parameters to the mm discrepancies ri(x)=modeli(x)−datair_i(x) = \text{model}_i(x) - \text{data}_i, and Jk∈Rm×nJ_k \in \mathbb{R}^{m \times n} has entries (Jk)ij=∂ri/∂xj(J_k)_{ij} = \partial r_i / \partial x_j evaluated at xkx_k. Requiring JkJ_k to have full column rank (m>nm > n) makes JkTJk∈Rn×nJ_k^{\mathsf T}J_k \in \mathbb{R}^{n \times n} symmetric positive definite.

$H\lt em>k$ vs $J\lt /em>k^{\mathsf T}J_k$ — exact Hessian against Gauss–Newton approximation

For f=12∥r∥22f = \tfrac12 \lVert r \rVert_2^2, the exact Hessian is Hk=JkTJk+∑i=1mri(xk)∇2ri(xk)H_k = J_k^{\mathsf T}J_k + \sum_{i=1}^{m} r_i(x_k)\nabla^2 r_i(x_k). Gauss–Newton keeps only the first-derivative term JkTJkJ_k^{\mathsf T}J_k, avoiding the mm second-derivative matrices ∇2ri\nabla^2 r_i while matching HkH_k whenever r(x∗)=0r(x^*) = 0.

$c$, $\lambda$, and $(t\lt em>i, y\lt /em>i)$ — the exponential-fit data

Here x=(c,λ)∈R2x = (c, \lambda) \in \mathbb{R}^{2} parameterises the curve y(t)=c eλty(t) = c\,e^{\lambda t}, so λ\lambda is a decay rate (not an eigenvalue of a Hessian as in §§1–4). The nine sample times ti∈[0,4]t_i \in [0, 4] and noisy measurements yiy_i are fixed data; changing ss changes the target yiy_i and therefore shifts the best-fit minimiser x∗x^*.

Descent methods use the slope only. Newton also uses the curvature: minimise the quadratic model f(xk)+gkTs+12sTHksf(x_k) + g_k^{\mathsf T} s + \tfrac12 s^{\mathsf T} H_k s, whose minimiser solves

Hk sk=−∇f(xk),xk+1=xk+sk.H_k\, s_k = -\nabla f(x_k), \qquad x_{k+1} = x_k + s_k .

On the quadratic of §1, H=AH = A and s0=−A−1(Ax0−b)s_0 = -A^{-1}(Ax_0 - b), so x1=A−1bx_1 = A^{-1}b in one step: the Newton step is the linear solve, and its cost is the solve. On a general smooth ff the model is exact to second order, and near a minimum with HH positive definite the error obeys ∥ek+1∥≤C∥ek∥2\|e_{k+1}\| \le C\|e_k\|^2.

Measure it as in M01. Below, Newton on the convex function f(x,y)=ex+3y−0.1+ex−3y−0.1+e−x−0.1f(x, y) = e^{x+3y-0.1} + e^{x-3y-0.1} + e^{-x-0.1}, minimum at (−12ln⁡2,0)(-\tfrac12\ln 2, 0), from (2,0.5)(2, 0.5). The observed order is pk=log⁡(∥ek∥/∥ek−1∥)/log⁡(∥ek−1∥/∥ek−2∥)p_k = \log(\|e_k\|/\|e_{k-1}\|) / \log(\|e_{k-1}\|/\|e_{k-2}\|).

kk error ∥xk−x∗∥\|x_k - x^*\| observed order
0 2.40e+00 —
1 1.47e+00 —
2 7.59e-01 1.36
3 3.91e-01 1.00
4 1.26e-01 1.72
5 1.32e-02 1.98
6 1.47e-04 2.00
7 1.79e-08 2.01

The first rows are pre-asymptotic, far enough away that the model is poor. Then the order settles at 2: each step doubles the number of correct digits, until the error meets the floor of double precision.

Gauss–Newton. A fit is a minimum of f(x)=12∥r(x)∥2f(x) = \tfrac12\|r(x)\|^2, with residuals ri=modeli(x)−datair_i = \text{model}_i(x) - \text{data}_i and Jacobian J=∂r/∂xJ = \partial r/\partial x. Differentiating twice,

∇f=JTr,∇2f=JTJ+∑iri∇2ri.\nabla f = J^{\mathsf T} r, \qquad \nabla^2 f = J^{\mathsf T} J + \textstyle\sum_i r_i \nabla^2 r_i .

Gauss–Newton drops the second term, which needs second derivatives and is small when the residuals are, and solves JTJ s=−JTrJ^{\mathsf T}J\,s = -J^{\mathsf T}r. Those are the normal equations of the linear least-squares problem min⁡s∥Js+r∥\min_s \|Js + r\|, and κ(JTJ)=κ(J)2\kappa(J^{\mathsf T}J) = \kappa(J)^2 (M03), so a careful code solves that problem by QR on JJ instead of forming JTJJ^{\mathsf T}J. With a zero residual at the fit the dropped term vanishes there and the rate is Newton's; with a misfit it is linear. Fitting a tyre model to rig data, a system the book's optimisation page lists, is this problem.

Below: fit y=c eλty = c\,e^{\lambda t} to nine points from c=2c = 2, λ=−0.5\lambda = -0.5, plus a fixed misfit pattern you can scale, starting at c=1c = 1, λ=0\lambda = 0.

kk error to the fit ratio ∥ek∥/∥ek−1∥\lVert e_k \rVert / \lVert e_{k-1} \rVert
0 1.13e+00 —
1 2.93e-01 2.6e-01
2 6.75e-03 2.3e-02
3 1.49e-05 2.2e-03
4 2.88e-08 1.9e-03
5 1.98e-10 6.9e-03
6 1.36e-12 6.9e-03
7 9.24e-15 —
8 0.00e+00 —

Fit c=2.0144c = 2.0144, λ=−0.5045\lambda = -0.5045, with residual 12∥r∥2\tfrac12\|r\|^2 = 1.30e-02; κ(J)=3.19\kappa(J) = 3.19 and κ(JTJ)=10.16\kappa(J^{\mathsf T}J) = 10.16. At zero misfit the ratio itself collapses towards zero: quadratic. With a misfit it levels off at a constant, which is linear convergence, and the constant grows with the misfit.

When Newton and Gauss–Newton breaks
  • Assumes: a start close enough that the quadratic model is good, and a Hessian (or JTJJ^{\mathsf T}J) that is positive definite there
  • When it fails: far from the minimum the pure Newton step can raise ff or head for a saddle; Gauss–Newton slows to linear when the residual at the fit is large
  • Check: check ff falls at every step (else damp it with a line search), and measure the observed order: 2 for Newton, less for Gauss–Newton on a misfit

6. Constraints: the KKT system and the compliant spring

Setting: the problem, its sets and its symbols

Problem. Given an SPD K∈Rn×nK \in \mathbb{R}^{n \times n}, f∈Rnf \in \mathbb{R}^{n}, a constraint matrix B∈Rm×nB \in \mathbb{R}^{m \times n} of full row rank (m<nm \lt n) and g∈Rmg \in \mathbb{R}^{m}, find u∈Rnu \in \mathbb{R}^{n} minimising 12uTKu−fTu\tfrac12 u^{\mathsf T}Ku - f^{\mathsf T}u subject to Bu=gBu = g, with its multipliers p∈Rmp \in \mathbb{R}^{m}. Then, for each stiffness k>0k > 0, find the unconstrained minimiser uku_k of EkE_k, and how the distance d(k)d(k) behaves in doubles as kk grows.

Symbol In Meaning
n, mn,\ m N\mathbb{N} unknowns and constraints; the example has n=2n = 2, m=1m = 1
uu Rn\mathbb{R}^{n} the displacements; the example is dimensionless, so no quantity in this section carries units
KK Rn×n\mathbb{R}^{n \times n} the stiffness matrix, SPD; the example is diag(2,3)\mathrm{diag}(2, 3)
ff Rn\mathbb{R}^{n} the applied loads; the example is (1,1)(1, 1)
B, gB,\ g Rm×n, Rm\mathbb{R}^{m \times n},\ \mathbb{R}^{m} the rule Bu=gBu = g; full row rank; the example is B=(1  1)B = (1\ \ 1), g=0.84g = 0.84
pp Rm\mathbb{R}^{m} the Lagrange multipliers; BTpB^{\mathsf T}p is the reaction force
L\mathcal L Rn×Rm→R\mathbb{R}^{n} \times \mathbb{R}^{m} \to \mathbb{R} the Lagrangian 12uTKu−fTu+pT(Bu−g)\tfrac12 u^{\mathsf T}Ku - f^{\mathsf T}u + p^{\mathsf T}(Bu - g)
kk (0,∞)(0, \infty) the bush stiffness; the slider sets log⁡10k∈[0,16]\log_{10} k \in [0, 16]
EkE_k Rn→R\mathbb{R}^{n} \to \mathbb{R} the penalised energy 12uTKu−fTu+k2∥Bu−g∥22\tfrac12 u^{\mathsf T}Ku - f^{\mathsf T}u + \tfrac{k}{2}\lVert Bu - g \rVert_2^2
uk, pku_k,\ p_k Rn, Rm\mathbb{R}^{n},\ \mathbb{R}^{m} the minimiser of EkE_k and the bush force k(Buk−g)k(Bu_k - g)
d(k)d(k) [0,∞)[0, \infty) the distance ∥uk−u∥2\lVert u_k - u \rVert_2 from the rigid answer, computed in doubles
κ(⋅)\kappa(\cdot) [1,∞)[1, \infty) the 2-norm condition number of an SPD matrix
ϵ\epsilon R>0\mathbb{R}_{>0} machine epsilon for doubles, 2−522^{-52}
How these symbols connect

Given an SPD stiffness matrix K∈Rn×nK \in \mathbb{R}^{n \times n}, loads f∈Rnf \in \mathbb{R}^{n}, and linear constraint Bu=gBu = g (B∈Rm×nB \in \mathbb{R}^{m \times n} of full row rank, g∈Rmg \in \mathbb{R}^{m}), introducing multipliers p∈Rmp \in \mathbb{R}^{m} builds the Lagrangian L(u,p)\mathcal L(u, p) whose stationary conditions give the rigid displacement u∈Rnu \in \mathbb{R}^{n} and reaction pp. Replacing the hard constraint with a penalty term weighted by stiffness k>0k > 0 forms the unconstrained energy Ek:Rn→RE_k : \mathbb{R}^{n} \to \mathbb{R}, yielding a compliant displacement uk∈Rnu_k \in \mathbb{R}^{n} and bush force pk=k(Buk−g)∈Rmp_k = k(Bu_k - g) \in \mathbb{R}^{m}. Comparing uku_k with uu in double precision (ϵ\epsilon) gives the distance d(k)=∥uk−u∥2d(k) = \lVert u_k - u \rVert_2, alongside the condition number κ(⋅)\kappa(\cdot) of the penalised Hessian; the example is dimensionless.

Symbol-by-symbol notes
$B$ and $g$ — full-row-rank linear constraints

B∈Rm×nB \in \mathbb{R}^{m \times n} has fewer rows than columns (m<nm \lt n) and full row rank mm, meaning the mm scalar constraints in Bu=gBu = g are linearly independent and leave n−mn - m free degrees of freedom. If rows of BB were dependent, the constraint would be either redundant or inconsistent.

$p$ and $B^{\mathsf T}p$ — Lagrange multipliers and reaction force

p∈Rmp \in \mathbb{R}^{m} has one entry per constraint row, while BTp∈RnB^{\mathsf T}p \in \mathbb{R}^{n} maps those multipliers back into the load space of ff as the generalised reaction force enforcing Bu=gBu = g. Do not confuse this multiplier pp with the convergence order pkp_k of §5 or the search direction pkp_k of §4.

$\mathcal L(u, p)$ — the Lagrangian and its saddle point

L\mathcal L takes both the primal unknown u∈Rnu \in \mathbb{R}^{n} and the dual unknown p∈Rmp \in \mathbb{R}^{m}, so its stationary point is found by setting both ∇uL=0\nabla_u \mathcal L = 0 and ∇pL=0\nabla_p \mathcal L = 0. Because pp enters linearly, L\mathcal L is unbounded below in pp and its stationary point is a saddle point rather than a minimum.

$k$, $E\lt em>k$, and $(u\lt /em>k, p_k)$ — the compliant penalty model

Here k>0k > 0 is a continuous real stiffness parameter (not an iteration index as in §§2–5), and Ek(u)E_k(u) adds the quadratic penalty k2∥Bu−g∥22\tfrac{k}{2}\lVert Bu - g \rVert_2^2 to the unconstrained energy. Its minimiser uku_k satisfies Buk≠gBu_k \ne g in general, and pk=k(Buk−g)p_k = k(Bu_k - g) is the resulting spring force that plays the role of pp.

$d(k)$ and $\kappa(\cdot)$ — rigid-limit error and conditioning

d(k)=∥uk−u∥2d(k) = \lVert u_k - u \rVert_2 measures the Euclidean distance between the double-precision compliant solution uku_k and the rigid KKT solution uu as kk sweeps from 10010^0 to 101610^{16}. Note that κ(⋅)\kappa(\cdot) is evaluated on the SPD Hessian of EkE_k, not on the indefinite KKT matrix.

Minimise 12uTKu−fTu\tfrac12 u^{\mathsf T}Ku - f^{\mathsf T}u subject to Bu=gBu = g. Add a multiplier pp per constraint and make the Lagrangian L=12uTKu−fTu+pT(Bu−g)\mathcal L = \tfrac12 u^{\mathsf T}Ku - f^{\mathsf T}u + p^{\mathsf T}(Bu - g) stationary in both:

(KBTB0)(up)=(fg).\begin{pmatrix} K & B^{\mathsf T} \\ B & 0 \end{pmatrix} \begin{pmatrix} u \\ p \end{pmatrix} = \begin{pmatrix} f \\ g \end{pmatrix} .

This is the KKT system, and BTpB^{\mathsf T}p is the force the rule exerts: pp is the reaction. The book's example, K=diag(2,3)K = \mathrm{diag}(2, 3), f=(1,1)f = (1, 1), B=(1  1)B = (1\ \ 1), g=0.84g = 0.84, gives u=(0.504,0.336)u = (0.504, 0.336) and p=−0.008p = -0.008. The matrix is symmetric but its eigenvalues are -0.651, 2.274, 3.377: indefinite. The solution is a saddle point of L\mathcal L, not a minimum, so CG does not apply; MINRES, a Schur-complement method or a direct factorisation with pivoting does.

The compliant version. Replace the rigid rule by a stiff bush of stiffness kk: Ek(u)=12uTKu−fTu+k2∥Bu−g∥2E_k(u) = \tfrac12 u^{\mathsf T}Ku - f^{\mathsf T}u + \tfrac{k}{2}\|Bu - g\|^2. Its minimum solves the SPD system (K+kBTB)u=f+kBTg(K + kB^{\mathsf T}B)u = f + kB^{\mathsf T}g, and the bush force pk=k(Buk−g)p_k = k(Bu_k - g) is the multiplier. Writing Buk−pk/k=gBu_k - p_k/k = g gives the regularised KKT system with −1/k-1/k in the corner: rigid is compliance zero. This is the S track's bushed suspension, and its stiffness ladder is the test below.

Predict first. Replace the rigid rule by a bush of stiffness kk and raise kk from 10410^4 to 101410^{14}. The distance from the rigid answer

Choose a prediction

Check answer (without scripting)

Answer: falls like 1/k, then grows again. Model error about C/kC/k plus rounding about ϵ κ∝ϵk\epsilon\,\kappa \propto \epsilon k. The sum is M01's V: a best stiffness, and worse on both sides of it.

Reveal result (lock in your prediction above first)
10⁰10⁴10⁸10¹²10¹⁶10⁻¹⁰10⁻⁸10⁻⁶10⁻⁴10⁻²bush stiffness kdistance from the rigid answer
kk uku_k bush force pkp_k rigid pp κ(K+kBTB)\kappa(K + kB^{\mathsf T}B)
10410^{4} (0.504000, 0.336000) -0.007999 -0.008000 8.0e+03

The distance falls tenfold per decade of kk and is smallest near k=108.25k = 10^{8.25}; above that the conditioning, about kk, costs more than the bush's softness. The force pkp_k loses its digits first, because it is kk times a tiny violation Buk−gBu_k - g: the multiplier page's "right displacements, wrong forces". A ladder of stiffnesses that keeps falling is the evidence; one very stiff run is not.

When the KKT system and its compliant version breaks
  • Assumes: the constraint rows BB are independent, and for the compliant form a stiffness far above the structure's
  • When it fails: redundant rows make the KKT matrix singular; a bush that is too soft gives the wrong answer, and one that is too stiff gives a Hessian too ill-conditioned to solve
  • Check: run a ladder of stiffnesses and require the distance to the rigid answer to fall steadily; a turn upwards is the round-off floor

Practice

Practice A (steps partly filled). A quadratic's Hessian has eigenvalues 0.50.5 and 88. Then κ=8/0.5=  ?\kappa = 8 / 0.5 = \;?, and steepest descent at the best fixed step contracts the error by (κ−1)/(κ+1)(\kappa - 1)/(\kappa + 1) per step. Enter that factor.

Worked solution

κ=16\kappa = 16, so the factor is 15/17≈0.88215/17 \approx 0.882, reached at t∗=2/(0.5+8)≈0.235t^* = 2/(0.5 + 8) \approx 0.235.

Practice B (with a hint). An SPD system has κ=400\kappa = 400. Using the CG bound 2((κ−1)/(κ+1))k≤10−62\big((\sqrt\kappa - 1)/(\sqrt\kappa + 1)\big)^k \le 10^{-6}, enter the smallest whole number of iterations kk that guarantees a 10−610^{-6} reduction in the AA-norm.

Worked solution

ln⁡(2×106)≈14.51\ln(2 \times 10^6) \approx 14.51 and ln⁡(21/19)≈0.1001\ln(21/19) \approx 0.1001, so k≥144.97k \ge 144.97: 145 iterations. Steepest descent's factor 399/401399/401 would need about 2760.

Hint 1

400=20\sqrt{400} = 20, so the factor is 19/2119/21.

Hint 2

Take logs: k≥ln⁡(2×106)/ln⁡(21/19)k \ge \ln(2 \times 10^{6}) / \ln(21/19), then round up.

Practice C (on your own). With K=diag(2,3)K = \mathrm{diag}(2, 3), f=(1,1)f = (1, 1) and the rule u1+u2=1u_1 + u_2 = 1, solve the KKT system and enter the multiplier pp.

Worked solution

From the first two rows u1=(1−p)/2u_1 = (1 - p)/2 and u2=(1−p)/3u_2 = (1 - p)/3. The rule gives (1−p)(1/2+1/3)=1(1 - p)(1/2 + 1/3) = 1, so 1−p=6/51 - p = 6/5 and p=−0.2p = -0.2, with u=(0.6,0.4)u = (0.6, 0.4). That is the Schur complement S=BK−1BT=5/6S = BK^{-1}B^{\mathsf T} = 5/6 at work.

Mixed practice. Which method, and why?

1. A sparse SPD system with 10610^6 unknowns and κ≈104\kappa \approx 10^4. Which method, and why?

Question 1

2. An unknown solver's error goes 10−2,10−4,10−810^{-2}, 10^{-4}, 10^{-8} over three steps. Which is it most likely?

Question 2

3. A Gauss–Newton fit has κ(J)=105\kappa(J) = 10^5. How should each step's linear least-squares problem be solved?

Question 3

Show answers and explanations

1. Conjugate gradients, preconditioned: about the square root of kappa steps. One sparse product per step and κ=100\sqrt{\kappa} = 100 sets the scale; a preconditioner shrinks the effective κ\kappa further.

2. Newton's method near the minimum. M01's observed order: log⁡(10−8/10−4)/log⁡(10−4/10−2)=2\log(10^{-8}/10^{-4})/\log(10^{-4}/10^{-2}) = 2, the signature of Newton.

3. By QR on J, because the normal equations square the condition number. κ(JTJ)=1010\kappa(J^{\mathsf T}J) = 10^{10} would leave about six digits in doubles; QR works with κ(J)\kappa(J) and keeps about eleven (M03).

Check yourself (closed book)

1. AA is symmetric positive definite. Where is the minimum of f(x)=12xTAx−bTxf(x) = \tfrac12 x^{\mathsf T} A x - b^{\mathsf T} x?

Question 1
How sure?

2. Gradient descent with a fixed step tt on a quadratic whose Hessian has eigenvalues 2 and 50. Which steps converge?

Question 2
How sure?

3. The condition number κ\kappa of AA grows a hundredfold. Roughly how do the iteration counts of steepest descent and of conjugate gradients change?

Question 3
How sure?

4. Steepest descent with an exact line search zig-zags across a narrow valley. Why?

Question 4
How sure?

5. AA is 1000×10001000 \times 1000, SPD, with only four distinct eigenvalues. In exact arithmetic conjugate gradients finishes in

Question 5
How sure?

6. Newton's method xk+1=xk−H−1∇f(xk)x_{k+1} = x_k - H^{-1}\nabla f(x_k) on f(x)=12xTAx−bTxf(x) = \tfrac12 x^{\mathsf T}Ax - b^{\mathsf T}x, from any start:

Question 6
How sure?

7. For f=12∥r(x)∥2f = \tfrac12\|r(x)\|^2 the Hessian is JTJ+∑iri∇2riJ^{\mathsf T}J + \sum_i r_i \nabla^2 r_i. What does Gauss–Newton drop, and when does that cost speed?

Question 7
How sure?

8. Why can conjugate gradients not be applied straight to the KKT matrix (KBTB0)\begin{pmatrix}K & B^{\mathsf T}\\ B & 0\end{pmatrix}?

Question 8
How sure?

9. A rigid constraint is replaced by a bush of stiffness kk. As kk rises, the distance from the rigid answer

Question 9
How sure?

Show answers and explanations

1. Where Ax = b, because the gradient is Ax - b. ∇f=Ax−b\nabla f = Ax - b vanishes only at x∗=A−1bx^* = A^{-1}b, and the Hessian AA is positive definite, so that stationary point is the unique minimum.

2. 0 < t < 0.04, two over the largest eigenvalue. Each mode is multiplied by 1−tλi1 - t\lambda_i; all shrink only if ∣1−tλi∣<1|1 - t\lambda_i| \lt 1 for every ii, so t<2/50t \lt 2/50.

3. Steepest descent a hundredfold, conjugate gradients tenfold. Steepest descent needs about κ2ln⁡(1/ε)\tfrac{\kappa}{2}\ln(1/\varepsilon) steps; CG's bound (κ−1)/(κ+1)(\sqrt\kappa-1)/(\sqrt\kappa+1) gives about κ2ln⁡(2/ε)\tfrac{\sqrt\kappa}{2}\ln(2/\varepsilon).

4. Each new gradient is orthogonal to the last step, so the path turns a right angle every time. At the exact minimum along gkg_k the slope along gkg_k is zero, so gk+1Tgk=0g_{k+1}^{\mathsf T} g_k = 0. In an elongated bowl that means short, perpendicular hops.

5. at most 4 iterations. A degree-4 polynomial with P(0)=1P(0) = 1 can vanish at all four eigenvalues, so the error is zero after four steps, whatever nn is.

6. lands on the minimum in one step. H=AH = A and ∇f=Ax0−b\nabla f = Ax_0 - b, so x1=x0−A−1(Ax0−b)=A−1bx_1 = x_0 - A^{-1}(Ax_0 - b) = A^{-1}b. The Newton step on a quadratic is the linear solve.

7. The residual-weighted second derivatives; it costs speed when the residuals at the fit stay large. With zero residual at the answer the dropped term vanishes there and Gauss–Newton is as fast as Newton. A misfit leaves it linear, with a factor that grows with the misfit.

8. It is indefinite: it has negative as well as positive eigenvalues. CG minimises 12zTMz−cTz\tfrac12 z^{\mathsf T}Mz - c^{\mathsf T}z, which has no minimum when MM has a negative eigenvalue. The solution is a saddle point; use MINRES, a block preconditioner or a direct solve.

9. falls like 1/k, then grows again once the conditioning costs more than the model error. Model error about C/kC/k plus rounding about ϵκ∝ϵk\epsilon\kappa \propto \epsilon k: the same V as a finite difference's round-off floor.

Keep these:

  1. Minimising 12xTAx−bTx\tfrac12 x^{\mathsf T}Ax - b^{\mathsf T}x with AA SPD is solving Ax=bAx = b; the gap to the minimum is 12∥e∥A2\tfrac12\|e\|_A^2.
  2. A fixed step needs 0<t<2/λmax⁡0 \lt t \lt 2/\lambda_{\max}; the best one contracts by (κ−1)/(κ+1)(\kappa - 1)/(\kappa + 1), so the step count grows like κ\kappa.
  3. A line search fixes the length, not the direction: steepest descent still zig-zags at the same rate.
  4. CG makes each direction AA-conjugate: exact after as many steps as there are eigenvalues in play, and about κ\sqrt\kappa steps per factor otherwise.
  5. Newton adds the curvature and converges with order 2; Gauss–Newton drops the residual term and is as fast only when the fit is exact.
  6. A constraint adds a multiplier and an indefinite KKT matrix; a stiff spring approximates it with error ∼1/k\sim 1/k until conditioning ∼k\sim k wins.

Your connection

Pick one minimisation you have run or relied on (a fit, a training run, a solver's equilibrium). What was its condition number likely to be, and what told you it had converged?

Answers

Practice A. κ=16\kappa = 16, factor 15/17≈0.88215/17 \approx 0.882.

Practice B. k=145k = 145.

Practice C. p=−0.2p = -0.2, u=(0.6,0.4)u = (0.6, 0.4).

Mixed practice. preconditioned CG; Newton (order 2); QR on JJ.

Where the maths is derived

Optional. These notes give the intuition and application; the sources below give the full derivations and proofs.

§1 A minimum is a linear solve

§2 The step window

§3 Conditioning sets the speed

§4 Conjugate gradients

§5 Newton and Gauss–Newton

§6 Constraints and the KKT system


Compiled from notebooks/methods/m04_optimisation.py — run locally with cd notebooks && uv run marimo edit methods/m04_optimisation.py for live Python scratch cells.

Back to the book: Optimisation · A step has a direction and a length

Settings

Colour scheme

Light or dark pages. Your colour and layout stay the same.

Colour

The paper, ink and lettering. Your layout stays the same.

Quiet colours
Bold colours
Reading offline

Keep this book on this device and read it offline.