Numerical Methods

All books

M08 — Choosing the class: one suspension corner, five ways

The class of a problem is not printed on the mechanism. It is a property of how the model was written down, and the method follows from the class. This notebook takes one suspension corner from solvers/otkd and poses it five ways: a square nonlinear system, an over-determined one, a rank-deficient one, a compliant one and a moving one. Then it reads the symptoms of a wrong solve, and the evidence that an answer is right.

Book pages: The class is a choice you make, The same corner, five ways, Saddle point, When it goes wrong and Knowing the answer is right in books/numerical-methods. The solver numbers are otkd's own, run live and cached.

The question. The same corner, the same parts. What decides whether you solve it with Newton, least squares, a KKT system or a time stepper, and how do you know the answer is right?

By the end you can:

  • classify a model from its rows, unknowns and rank, and name the solve that follows
  • find a redundant row with the SVD, and say why it is not a zero singular value
  • write a compliant joint as a KKT saddle point, and trade it against a penalty
  • say why a stiff tyre spring sets an explicit time step, and what replacing it with a constraint buys
  • read a residual history as a diagnosis: linear, oscillating, stalled, singular
  • check an answer with a bound, a second method, a limit case and a conserved quantity

Assumes: M01–M07: order, Newton, linear systems and the SVD, optimisation and KKT, eigenvalues and modes, equation classes and implicit steps, Monte Carlo.

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: the two-leg corner has 22 rows and 21 unknowns, and one row is redundant. Its Jacobian is a 22×2122 \times 21 matrix. How many of its singular values are zero?

Choose a prediction

Check answer (without scripting)

Answer: None. Rank 21 with 21 singular values leaves no zero. The spare row shows as a vector uu with uTJ=0u^{\mathsf T} J = 0: a combination of rows, not a singular value.

Warm-up: remember

1. Antithetic pairs average f(U)f(U) and f(1−U)f(1 - U). When do they reduce the variance per evaluation?

Question 1
How sure?

2. An explicit heat solve at fixed rr reaches t=1t = 1. You halve Δx\Delta x. The work grows by about

Question 2
How sure?

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

Question 3
How sure?

Show answers and explanations

1. When f is monotone, so the pair is negatively correlated. The pair's variance is 12(σ2+Cov)\tfrac12(\sigma^2 + \mathrm{Cov}); it beats two independent draws only when the covariance is negative, which monotone ff guarantees.

2. a factor of 8. Four times the steps, because Δt∝Δx2\Delta t \propto \Delta x^2, times twice the nodes per step.

3. 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.

1. Where is the wheel: a square system, and Newton

Setting: the problem, its sets and its symbols

Problem. Given the corner's rows r(⋅ ;θ):Rn→Rmr(\cdot\,; \theta) : \mathbb{R}^n \to \mathbb{R}^m at a driver angle θ\theta, find the pose q∈Rnq \in \mathbb{R}^n with r(q;θ)=0r(q; \theta) = 0. In the plane, given two circles, find the upper ball joint p∈R2p \in \mathbb{R}^2 with F(p)=0F(p) = 0, and say which of its roots Newton returns from p0p_0.

Symbol In Meaning
qq Rn\mathbb{R}^n the unknowns: seven pose coordinates per moving body, a position (m) and a unit quaternion
n, mn,\ m N\mathbb{N} the numbers of unknowns and rows, as otkd's check reports them
θ\theta R\mathbb{R} the driver: the lower arm's angle (rad), 0.1 here
rr Rn→Rm\mathbb{R}^n \to \mathbb{R}^m the rows: joint constraints, one driver row and one norm per quaternion
JJ Rm×n\mathbb{R}^{m \times n} the Jacobian ∂r/∂q\partial r/\partial q
mobility, redundancy\text{mobility},\ \text{redundancy} N\mathbb{N} nn minus the rank of the constraint rows; rows minus rank
qk, Δqq_k,\ \Delta q Rn\mathbb{R}^n Newton's iterates and step, J(qk) Δq=−r(qk)J(q_k)\,\Delta q = -r(q_k)
eke_k [0,∞)[0, \infty) the error ∥qk−q∗∥\lVert q_k - q^* \rVert at a root q∗q^*
p=(x,z)p = (x, z) R2\mathbb{R}^2 the upper ball joint in front view (m)
c1, c2c_1,\ c_2 R2\mathbb{R}^2 the circles' centres: the upper arm's hinge axis and the lower ball joint (m)
ρ1, ρ2\rho_1,\ \rho_2 (0,∞)(0, \infty) their radii (m): the upper arm, and the upright between the ball joints
FF R2→R2\mathbb{R}^2 \to \mathbb{R}^2 the two rules Fi(p)=∥p−ci∥2−ρi2F_i(p) = \lVert p - c_i \rVert^2 - \rho_i^2 (m²)
p0p_0 R2\mathbb{R}^2 the starting guess (0.55,z0)(0.55, z_0), with z0z_0 on the slider
How these symbols connect

Fixing the driver angle θ\theta defines the 3-D residual map r(⋅ ;θ):Rn→Rmr(\cdot\,; \theta) : \mathbb{R}^n \to \mathbb{R}^m, whose Jacobian J=∂r/∂qJ = \partial r/\partial q determines mobility\text{mobility} and redundancy\text{redundancy}. When m=nm = n and JJ has full rank, Newton linearises r(qk+Δq)≈0r(q_k + \Delta q) \approx 0 into J(qk) Δq=−r(qk)J(q_k)\,\Delta q = -r(q_k) to reduce the error ek=∥qk−q∗∥e_k = \lVert q_k - q^* \rVert. In the 2-D front-view slice, the same iteration maps the upper ball joint p=(x,z)p = (x, z) through the two circle equations F(p)=0F(p) = 0 set by centres c1,c2c_1, c_2 and radii ρ1,ρ2\rho_1, \rho_2, starting from p0p_0.

Symbol-by-symbol notes
$q$ and the quaternion norms

Each moving body carries 77 coordinates: 33 for position (m) and 44 for a unit quaternion describing orientation. Because a quaternion has one extra component, rr includes one unit-norm row per moving body alongside the joint rows and the driver row.

$\text{mobility}$ versus $\text{redundancy}$

mobility\text{mobility} is nn minus the rank of the constraint rows alone (the free motions before the driver acts). redundancy\text{redundancy} is total rows minus the rank of all rows (spare equations); zero redundancy with m=nm = n makes the system square.

$r$ (3-D) versus $F$ (2-D)

r:Rn→Rmr : \mathbb{R}^n \to \mathbb{R}^m is otkd's full 3-D corner system at angle θ\theta, whereas F:R2→R2F : \mathbb{R}^2 \to \mathbb{R}^2 isolates the upper ball joint p=(x,z)p = (x, z) as the intersection of two circles in front view. Writing Fi(p)=∥p−ci∥2−ρi2F_i(p) = \lVert p - c_i \rVert^2 - \rho_i^2 avoids square roots and gives residual units of m2\text{m}^2.

$p_0$ and multiple roots

Two intersecting circles generically meet at two distinct points, both solving F(p)=0F(p) = 0 to round-off. Which assembly Newton reaches depends on the starting guess p0=(0.55,z0)p_0 = (0.55, z_0), not on the size of the residual.

Fix the lower arm's angle. The upper ball joint must then sit on a circle about the upper arm's hinge, and at a fixed distance from the lower ball joint. Two rules, two unknowns: a root problem. otkd writes the same corner in three dimensions: seven pose coordinates per moving body (a position and a unit quaternion), so n=21n = 21 unknowns, and 21 rows (the joints, one driver row that sets the arm angle, and three quaternion norms). Its check reports:

unknowns rows rank of the constraint rows mobility n−rankn - \text{rank} actuators redundancy
21 21 20 1 1 0

The constraint rows leave one free motion, the actuator's driver row closes it, and no row is spare. Rows equal rank equal nn: square, so otkd calls Newton. That choice is made from the rank of the symbolic Jacobian, never from a flag.

Newton replaces r(q+Δq)=0r(q + \Delta q) = 0 by its linearisation r(q)+J Δq=0r(q) + J\,\Delta q = 0 and solves J Δq=−rJ\,\Delta q = -r. Near a simple root the error obeys ek+1≈Cek2e_{k+1} \approx C e_k^2, so the number of correct digits roughly doubles each step.

Two circles meet twice. In the plane, the upper ball joint is the intersection of those two circles, with centres and radii taken from otkd's design geometry. Both intersections are real assemblies of the same parts. Move the starting guess and watch which one Newton returns.

Hinge centre (0.380,0.475)(0.380, 0.475), radius 0.3034 m; lower ball joint (0.720,0.150)(0.720, 0.150), radius 0.3722 m. From (0.55,0.60)(0.55, 0.60) Newton reaches (0.6800,0.5200)(0.6800, 0.5200) in 5 steps: the design assembly. The residual at either answer is at round-off, so the residual cannot tell you which one you have; only the pose, compared with the last frame, can.

The corner itself. otkd's Newton, driven from the design pose to a lower-arm angle of 0.1 rad. Correct digits are −log⁡10-\log_{10} of the residual; their ratio step to step tends to the order. The last step is capped by round-off.

0123410⁻¹⁶10⁻¹²10⁻⁸10⁻⁴Newton stepmax |r|
step residual correct digits ratio to previous
0 1.00e-01 1.0
1 4.71e-03 2.3 2.33
2 1.21e-05 4.9 2.11
3 1.82e-09 8.7 1.78
4 3.18e-16 15.5 1.77

Condition number of JJ at the answer: 46.8.

source: `open_textbook.otkd.solvers.newton.newton` — `solvers/otkd/src/open_textbook/otkd/solvers/newton.py:11`
def newton(
    system: System,
    q0: np.ndarray,
    *,
    rows: list[int] | None = None,
    tol: float = 1e-12,
    max_steps: int = 60,
) -> tuple[np.ndarray, int, list[tuple[np.ndarray, np.ndarray]]]:
    """Solve `rows(q) = 0` from `q0`. Returns the solution, step count and residual history."""
    q = np.array(q0, dtype=float)
    history: list[tuple[np.ndarray, np.ndarray]] = []
    for step in range(max_steps):
        r = system.residual(q, rows)
        history.append((q.copy(), r.copy()))
        error = float(np.max(np.abs(r))) if r.size else 0.0
        if error < tol:
            return q, step, history
        jac = system.jacobian(q, rows)
        try:
            delta = np.linalg.solve(jac, -r)
        except np.linalg.LinAlgError:
            delta, *_ = np.linalg.lstsq(jac, -r, rcond=None)
        if not np.all(np.isfinite(delta)):
            raise SolverError("Newton step is not finite", residual=error)
        base = float(np.max(np.abs(r)))
        alpha = 1.0
        for _ in range(40):
            trial = q + alpha * delta
            if float(np.max(np.abs(system.residual(trial, rows)))) < base or alpha < 1e-8:
                break
            alpha *= 0.5
        q = q + alpha * delta

    r = system.residual(q, rows)
    index = (rows or system.constrained)[int(np.argmax(np.abs(r)))]
    raise SolverError(
        f"Newton did not converge in {max_steps} steps: |r|inf = {np.max(np.abs(r)):.3e}, "
        f"worst row {system.problem.rows[index].name}",
        residual=float(np.max(np.abs(r))),
    )
When Newton on the square corner breaks
  • Assumes: the Jacobian is nonsingular near the root, and the start lies in the basin of the assembly you want
  • When it fails: at a toggle the Jacobian is singular and convergence drops to linear or stops; from the other basin Newton returns the other assembly, with a residual just as small
  • Check: the rank and condition of JJ at the answer, and the pose against the previous frame (otkd flags a jump of 0.25 rad or 0.05 m as a branch change)

2. A spare row: least squares, and the SVD that names it

Setting: the problem, its sets and its symbols

Problem. Given the two-leg corner's rows r:Rn→Rmr : \mathbb{R}^n \to \mathbb{R}^m with m>nm > n, find q∈Rnq \in \mathbb{R}^n minimising ϕ(q)=12∥r(q)∥2\phi(q) = \tfrac12 \lVert r(q) \rVert^2, and find which rows are dependent: the vectors u∈Rmu \in \mathbb{R}^m with uTJ=0u^{\mathsf T} J = 0.

Symbol In Meaning
qq Rn\mathbb{R}^n the unknowns, as in §1: a position (m) and a unit quaternion per moving body
n, mn,\ m N\mathbb{N} the numbers of unknowns and rows
rr Rn→Rm\mathbb{R}^n \to \mathbb{R}^m §1's rows, with the upper hinge replaced by a front and a rear ball joint
ϕ\phi Rn→[0,∞)\mathbb{R}^n \to [0, \infty) the least-squares cost
JJ Rm×n\mathbb{R}^{m \times n} the Jacobian ∂r/∂q\partial r/\partial q at the answer
Δq\Delta q Rn\mathbb{R}^n the Gauss–Newton step, JTJ Δq=−JTrJ^{\mathsf T} J\,\Delta q = -J^{\mathsf T} r
U, Σ, VU,\ \Sigma,\ V Rm×m, Rm×n, Rn×n\mathbb{R}^{m \times m},\ \mathbb{R}^{m \times n},\ \mathbb{R}^{n \times n} the SVD J=UΣVTJ = U \Sigma V^{\mathsf T}: UU, VV orthogonal, Σ\Sigma diagonal with the singular values σi≥0\sigma_i \ge 0
ker⁡J\ker J ⊆Rn\subseteq \mathbb{R}^n the right null space: motions the rows allow
u∈ker⁡JTu \in \ker J^{\mathsf T} ⊆Rm\subseteq \mathbb{R}^m the left null space: weights under which a sum of rows vanishes identically
redundancy\text{redundancy} N\mathbb{N} rows minus the rank of all rows
J−iJ_{-i} R(m−1)×n\mathbb{R}^{(m-1) \times n} JJ with row ii dropped (the dropdown)
How these symbols connect

Replacing the upper hinge with two ball joints adds rows so m>nm > n; instead of solving r(q)=0r(q) = 0 directly, least squares minimises the scalar cost ϕ(q)=12∥r(q)∥2\phi(q) = \tfrac12\lVert r(q)\rVert^2 with Gauss–Newton steps Δq\Delta q built from J=∂r/∂qJ = \partial r/\partial q. At the solution, the SVD J=UΣVTJ = U\Sigma V^{\mathsf T} separates ker⁡J\ker J (allowed motions in Rn\mathbb{R}^n) from ker⁡JT\ker J^{\mathsf T} (row dependencies in Rm\mathbb{R}^m, counted by redundancy\text{redundancy}). Deleting row ii forms J−iJ_{-i} so you can test which single row can be dropped without losing rank.

Symbol-by-symbol notes
$\phi$ and the Gauss–Newton step $\Delta q$

Minimising ϕ(q)=12∥r(q)∥2\phi(q) = \tfrac12\lVert r(q)\rVert^2 turns an over-determined system into an unconstrained optimisation problem. Linearising r(q+Δq)≈r(q)+J Δqr(q + \Delta q) \approx r(q) + J\,\Delta q yields the normal equations JTJ Δq=−JTrJ^{\mathsf T} J\,\Delta q = -J^{\mathsf T} r, which remain n×nn \times n even though JJ is m×nm \times n.

$U$, $\Sigma$ and $V$

In the full SVD J=UΣVTJ = U\Sigma V^{\mathsf T}, U∈Rm×mU \in \mathbb{R}^{m \times m} and V∈Rn×nV \in \mathbb{R}^{n \times n} are orthogonal, while Σ∈Rm×n\Sigma \in \mathbb{R}^{m \times n} is rectangular with the non-negative singular values σi\sigma_i on its main diagonal. Columns of VV span the pose space Rn\mathbb{R}^n, and columns of UU span the row space Rm\mathbb{R}^m.

$\ker J$ versus $\ker J^{\mathsf T}$

A vector v∈ker⁡J⊆Rnv \in \ker J \subseteq \mathbb{R}^n satisfies Jv=0J v = 0 and represents an infinitesimal motion permitted by all rows (the right null space). A vector u∈ker⁡JT⊆Rmu \in \ker J^{\mathsf T} \subseteq \mathbb{R}^m satisfies uTJ=0u^{\mathsf T} J = 0 and gives weights for a linear combination of rows that vanishes identically (the left null space).

$J_{-i}$

J−i∈R(m−1)×nJ_{-i} \in \mathbb{R}^{(m-1) \times n} is JJ with row ii removed. Checking the rank of J−iJ_{-i} across candidate rows distinguishes a redundant row from an independent constraint.

Replace the upper arm's hinge by two ball joints, a front leg and a rear leg. A body held at two points can still turn about the line through them, so the second leg adds rows but no new restriction: 22 rows, n=21n = 21 unknowns. All rows together have rank 21, so redundancy is 22 − 21 = 1; the constraint rows have rank 20, so the mobility is still 1. Rows exceed rank, and rank equals nn: redundant, so otkd calls least squares and then diagnoses.

Least squares minimises 12∥r(q)∥2\tfrac12\|r(q)\|^2. Its Gauss–Newton step solves J Δq≈−rJ\,\Delta q \approx -r in the least-squares sense, JTJ Δq=−JTrJ^{\mathsf T} J\,\Delta q = -J^{\mathsf T} r. Because the spare row agrees with the others, the minimum is an exact solution: the residual history is 1.0e-01, 4.7e-03, 1.2e-05, 1.8e-09, 3.7e-16, the same digits as Newton in §1. The final cost is 1.1e-31. That says the rows are consistent, not that the answer is right.

The SVD writes J=UΣVTJ = U \Sigma V^{\mathsf T}. Columns of VV with σ=0\sigma = 0 are motions the rows allow (the right null space). Columns of UU beyond the rank satisfy uTJ=0u^{\mathsf T} J = 0: a weighted sum of rows that vanishes identically, which is what a dependence among rows is (the left null space). Your prediction at the top is answered here.

Reveal result (lock in your prediction above first)
1611162110⁻¹10⁰singular value numberσ
uca-front.ty-0.699uca-front.tz-0.035uca-rear.ty0.699uca-rear.tz0.035uca.unit0.14weight in the left null vector

21 singular values, the smallest 0.088: none is zero, and the condition number is 46.8. The redundancy is the one left null vector, supported on uca-front.ty, uca-front.tz, uca-rear.ty, uca-rear.tz, uca.unit. Between them, the two legs' yy and zz rows and the upper arm's quaternion norm say one thing twice: the arm is held at two points on its own axis.

Which row is the spare one? Drop one row and look at what is left.

Without uca-front.ty: rank 21 of n=21n = 21, condition 46.8. square again: Newton, and the same answer. otkd's study-square.yaml drops uca-front.ty, and Newton on that square system matches least squares to 9.1e-16 in every pose coordinate.

source: `open_textbook.otkd.solvers.svd.diagnose` — `solvers/otkd/src/open_textbook/otkd/solvers/svd.py:23`

otkd's diagnosis: one SVD, one tolerance for the rank and for naming rows.

def diagnose(system: System, q: np.ndarray, *, rows: list[int] | None = None, rtol: float = 1e-10) -> Diagnosis:
    """Rank, left null space and participating row names at `q`.

    `rtol` governs both decisions: singular values at or below `rtol * s[0]` are
    treated as zero when computing `rank`, and rows whose largest left-null
    coefficient exceeds `rtol` are named in `dependent_rows`.
    """
    rows = system.constrained if rows is None else rows
    jac = system.jacobian(q, rows)
    rank, null, s = left_null(jac, rtol=rtol)
    names = [system.problem.rows[i].name for i in rows]
    if null.shape[1]:
        weight = np.max(np.abs(null), axis=1)
        dependent = tuple(name for name, w in zip(names, weight) if w > rtol)
    else:
        dependent = ()
    condition = float(s[0] / s[rank - 1]) if rank else float("inf")
    return Diagnosis(
        singular_values=s,
        rank=rank,
        redundancy=len(rows) - rank,
        dependent_rows=dependent,
        null_space=null,
        condition=condition,
    )
When least squares with an SVD diagnosis breaks
  • Assumes: the redundant rows agree with each other, and the rank tolerance sits in a clear gap between the singular values
  • When it fails: with an inconsistency, least squares returns a compromise that satisfies no row and stalls at a residual floor; a tolerance inside a cluster of small singular values names the wrong rank
  • Check: the final residual should reach round-off (the cost is not proof); drop one named row and compare the square Newton answer

3. A compliant joint: constrained minimisation and the KKT saddle point

Setting: the problem, its sets and its symbols

Problem. Given the tie rod's compliance c>0c > 0 and the loads FF, find the pose q∈Rnq \in \mathbb{R}^n minimising the energy Π(q)\Pi(q) subject to the rigid rows Φ(q)=0\Phi(q) = 0; equivalently, find (q,λ)∈Rn×Rm(q, \lambda) \in \mathbb{R}^n \times \mathbb{R}^m with ∇Π(q)+BTλ=0\nabla \Pi(q) + B^{\mathsf T} \lambda = 0 and Φ(q)=0\Phi(q) = 0.

Symbol In Meaning
qq Rn\mathbb{R}^n the unknowns: a position (m) and a unit quaternion per moving body
Φ\Phi Rn→Rm\mathbb{R}^n \to \mathbb{R}^m the rigid rows: joints, quaternion norms and the driver
gg Rn→R\mathbb{R}^n \to \mathbb{R} the tie rod's extension (m)
cc (0,∞)(0, \infty) its compliance (m/N); the stiffness is 1/c1/c
F, x(q)F,\ x(q) R3 per load\mathbb{R}^3 \text{ per load} the loads (N) and the positions of the points they act at (m); F⋅xF \cdot x is their work (J)
Π\Pi Rn→R\mathbb{R}^n \to \mathbb{R} the energy g2/(2c)−F⋅xg^2/(2c) - F \cdot x (J)
λ\lambda Rm\mathbb{R}^m the multipliers: the reaction in each rigid row
LL Rn×Rm→R\mathbb{R}^n \times \mathbb{R}^m \to \mathbb{R} the Lagrangian Π+λTΦ\Pi + \lambda^{\mathsf T} \Phi
HH Rn×n\mathbb{R}^{n \times n} the Hessian ∇q2L\nabla_q^2 L
BB Rm×n\mathbb{R}^{m \times n} the rigid rows' Jacobian Φq\Phi_q
aa Rn\mathbb{R}^n the tie-rod row ∇g\nabla g
zz ker⁡B⊆Rn\ker B \subseteq \mathbb{R}^n a unit vector along the free motion
KK R(n+m)×(n+m)\mathbb{R}^{(n+m) \times (n+m)} the KKT matrix, the Newton matrix of the stationarity equations
kk (0,∞)(0, \infty) the penalty stiffness that replaces the multipliers (the slider)
kbushk_{\text{bush}} (0,∞)(0, \infty) the stiffness of each bush component at the upper ball joint, swept in otkd's double-wishbone-ubj payload (MN/m)
κ\kappa [1,∞)[1, \infty) a condition number
x, λx,\ \lambda R\mathbb{R} in the book's smallest case only: minimise 12x2−2x\tfrac12 x^2 - 2x subject to x=1x = 1
How these symbols connect

Turning the tie rod into a spring of compliance cc combines its extension g(q)g(q) and the external work F⋅x(q)F \cdot x(q) into the potential energy Π(q)=g(q)2/(2c)−F⋅x(q)\Pi(q) = g(q)^2/(2c) - F \cdot x(q) (J), minimised subject to the rigid rows Φ(q)=0\Phi(q) = 0. Pairing Π\Pi with multipliers λ\lambda in the Lagrangian L=Π+λTΦL = \Pi + \lambda^{\mathsf T}\Phi gives stationarity equations whose Newton matrix is the KKT matrix KK, assembled from H=∇q2LH = \nabla_q^2 L and B=ΦqB = \Phi_q (with tie-rod gradient a=∇ga = \nabla g and free-motion vector z∈ker⁡Bz \in \ker B). Replacing λ\lambda by a penalty stiffness kk (or physical bush stiffness kbushk_{\text{bush}}) gives an unconstrained formulation whose condition number κ\kappa can be compared against KK.

Symbol-by-symbol notes
$c$ versus $k$ and $k_{\text{bush}}$

Compliance cc has units m/N\text{m/N}, the reciprocal of stiffness 1/c1/c (N/m\text{N/m}), and belongs to the physical tie-rod spring. By contrast, kk is a numerical penalty stiffness placed on the rigid rows Φ\Phi, while kbushk_{\text{bush}} (MN/m\text{MN/m}) is the physical bush stiffness swept in otkd's double-wishbone-ubj payload.

$\lambda$ and its sign

Each entry of λ∈Rm\lambda \in \mathbb{R}^m is the Lagrange multiplier enforcing one row of Φ(q)=0\Phi(q) = 0, carrying units of generalised reaction force (energy per unit of that constraint row). Note that otkd's solver uses the opposite sign convention for λ\lambda from L=Π+λTΦL = \Pi + \lambda^{\mathsf T}\Phi.

$H$, $B$, $a$ and $z$

B=Φq∈Rm×nB = \Phi_q \in \mathbb{R}^{m \times n} linearises the rigid rows, while a=∇g∈Rna = \nabla g \in \mathbb{R}^n is the tie-rod gradient (giving aaT/ca a^{\mathsf T}/c as the Gauss–Newton part of HH). A unit vector z∈ker⁡Bz \in \ker B satisfies Bz=0B z = 0, pointing along the single free motion left by the rigid rows.

$K$ and $\kappa$

K∈R(n+m)×(n+m)K \in \mathbb{R}^{(n+m) \times (n+m)} packs HH, BB, BTB^{\mathsf T} and an m×mm \times m zero block into the Newton matrix for (q,λ)(q, \lambda). The condition number κ≥1\kappa \ge 1 tracks linear-solve sensitivity, allowing a direct comparison between KK and the penalised Hessian H+kBTBH + k B^{\mathsf T} B.

$(x, \lambda)$ in the scalar example

In the book's smallest case only, x∈Rx \in \mathbb{R} is a single scalar unknown (not a 3-D load application point x(q)∈R3x(q) \in \mathbb{R}^3) and λ∈R\lambda \in \mathbb{R} is the single multiplier enforcing x=1x = 1.

Make the tie rod's length a spring of compliance c=10−6c = 10^{-6} m/N and load the wheel centre with -3500 N in zz and 1800 N in xx (the study file's loads). Now nothing prescribes the free motion; the energy does. The equilibrium minimises

Π(q)=g(q)22c−F⋅x(q)subject toΦ(q)=0,\Pi(q) = \frac{g(q)^2}{2c} - F \cdot x(q) \quad \text{subject to} \quad \Phi(q) = 0,

where gg is the tie rod's extension and Φ\Phi the 20 rigid rows (16 joint rows, 3 norms, the driver). With L=Π+λTΦL = \Pi + \lambda^{\mathsf T}\Phi, stationarity is ∇Π+ΦqTλ=0\nabla\Pi + \Phi_q^{\mathsf T}\lambda = 0 and Φ=0\Phi = 0; its Newton matrix is the KKT matrix

K=[HBTB0],H=∇2L,B=Φq.K = \begin{bmatrix} H & B^{\mathsf T} \\ B & 0 \end{bmatrix}, \qquad H = \nabla^2 L, \quad B = \Phi_q .

λ\lambda is the reaction in every rigid row: the force comes out as part of the answer (otkd uses the opposite sign for λ\lambda). The book's smallest case: minimise 12x2−2x\tfrac12 x^2 - 2x subject to x=1x = 1 gives K=[1110]K = \begin{bmatrix} 1 & 1 \\ 1 & 0 \end{bmatrix}, solved by x=1x = 1, λ=1\lambda = 1.

Predict first. The compliant corner's KKT matrix is 41×4141 \times 41: 21 unknowns and 20 rigid rows. How many of its eigenvalues are negative?

Choose a prediction

Check answer (without scripting)

Answer: 20, one per rigid row. With BB of full row rank and HH positive on the null space of BB, the inertia is (n,m,0)=(21,20,0)(n, m, 0) = (21, 20, 0). Each constraint contributes one negative direction.

Reveal result (lock in your prediction above first)

The book's smallest case first: its KK has eigenvalues -0.618 and 1.618, one of each sign. The solution is a minimum in xx and a maximum in λ\lambda, a saddle point.

Built from otkd's Jacobian at the design pose, with H=aaT/cH = a a^{\mathsf T}/c (the Gauss–Newton part of the spring's Hessian; aa is the tie-rod row): 21 positive, 20 negative, 0 zero. HH alone has rank 1, yet KK is nonsingular, because HH is positive on the one free motion: zTHzz^{\mathsf T} H z is 1.64e+04 for the unit null vector zz of BB. Cholesky and conjugate gradients need positive definiteness, so the solve is a symmetric indefinite factorisation, MINRES, or (in otkd) least squares on the KKT residual.

The other way to write it. Drop the multipliers and replace every rigid row by a stiff spring: minimise Π(q)+k2∥Φ(q)∥2\Pi(q) + \tfrac{k}{2}\|\Phi(q)\|^2 with no constraint at all. The Hessian becomes H+kBTBH + k B^{\mathsf T} B: symmetric, positive definite, Cholesky-ready. The price is in two places. The rows are now met only to about force / k/\,k, and, once kk is above the spring's own 1/c1/c, the stiff directions grow with kk while the free motion does not, so the condition number grows like kk. Move kk.

10⁴10⁶10⁸10¹⁰10¹²10³10⁵10⁷10⁹penalty stiffness kcond(H + k BᵀB)

At k=108k = 10^{8} the penalised Hessian's condition number is 8.98e+04. The KKT matrix's is 2.99e+07 at every kk, because it has no kk. That number is not small: it mixes the spring's 1/c1/c with rows of order 1, and scaling the blocks would bring it down. What matters is that it does not grow, while the penalty's passes it near k=1011k = 10^{11} and keeps climbing. Below 1/c1/c the penalty is not yet the rigid model at all: the curve's left arm is the rigid rows being softer than the spring.

The bushed corner in the book is this penalty, made physical. The upper ball joint becomes a bush (three compliant components), and otkd's committed double-wishbone-ubj payload sweeps its stiffness. At rest the bushed camber differs from the rigid one by:

| bush stiffness (MN/m) | |camber difference from rigid| at rest (deg) | | --- | --- | | 0.2 | 0.9086 | | 1 | 0.1796 | | 10 | 0.0179 | | 100 | 0.0018 |

Each tenfold stiffness divides the difference by 5.06, 10.03, 9.94: first order in the compliance, the 1/k1/k of the penalty. The book's 1.8 MN/m is the stiffness at which that difference is a tenth of a degree.

source: `open_textbook.otkd.solvers.equilibrium.equilibrium` — `solvers/otkd/src/open_textbook/otkd/solvers/equilibrium.py:34`

otkd solves the KKT residual in (q,λ)(q, \lambda), scaled by the load.

def equilibrium(
    system: System,
    q0: np.ndarray,
    loads: LoadCase,
    *,
    tol: float = 1e-12,
) -> tuple[np.ndarray, int, list[tuple[np.ndarray, np.ndarray]]]:
    problem = system.problem
    rows = system.constrained
    springs = system.springs
    n = problem.n
    free = n - len(rows)
    if free < 1:
        raise SolverError("equilibrium needs at least one compliant degree of freedom")
    force_scale = max(1.0, float(sum(np.linalg.norm(force) for _, _, force in loads)))
    history: list[tuple[np.ndarray, np.ndarray]] = []

    def residual(x: np.ndarray) -> np.ndarray:
        q, lam = x[:n], x[n:]
        grad = problem.gradient(q, system.g, system.theta, springs)
        for body, point, force in loads:
            point_jac, _ = problem.point_derivatives(body, point)
            jacobian = np.asarray(point_jac(*q, *system.g), dtype=float).reshape(3, n)
            grad = grad - jacobian.T @ force
        stationarity = (grad - system.jacobian(q, rows).T @ lam) / force_scale
        return np.concatenate([stationarity, system.residual(q, rows)])

    def record(x: np.ndarray, *args) -> None:
        """Accepted iterates only, so `iterations[]` means what it means elsewhere."""
        history.append((np.asarray(x[:n]).copy(), residual(x)))

    start = np.concatenate([np.asarray(q0, dtype=float), np.zeros(len(rows))])
    # `max_nfev` is generous because a joint at 100 MN/m needs a few hundred evaluations on the
    # frame where the load first swings it; a well-behaved frame uses five.
    result = scipy_least_squares(
        residual,
        start,
        method="trf",
        x_scale="jac",
        callback=record,
        xtol=tol,
        ftol=tol,
        gtol=tol,
        max_nfev=1000,
    )
    # The two blocks are measured separately, because they are not the same unit: a constraint
    # left at 1e-8 is a metre of violation, which is a different claim from a force balance left
    # at 1e-8 of the load.
    constraints = float(np.max(np.abs(result.fun[n:]))) if len(rows) else 0.0
    stationarity = float(np.max(np.abs(result.fun[:n])))
    if constraints > 1e-12 or stationarity > 1e-9:
        raise SolverError(
            f"equilibrium did not converge: {result.message}",
            residual=max(constraints, stationarity),
        )
    return result.x[:n], int(result.nfev), history
When the KKT saddle point, and the penalty that replaces it breaks
  • Assumes: BB has full row rank and HH is positive on the null space of BB
  • When it fails: a redundant constraint makes the KKT matrix singular and the multipliers non-unique; a penalty leaves a constraint error near 1/k1/k and a condition number near kk; with no load the compliance is invisible and the stiffness ladder passes vacuously
  • Check: count the inertia (nn positive, mm negative), and sweep the stiffness: the difference from the rigid model should fall tenfold per decade

4. A moving corner: time stepping, stiffness and modes

Setting: the problem, its sets and its symbols

Problem. Given the mass matrix MM, the applied forces ff, the rows Φ\Phi and a start (q0,q˙0)(q_0, \dot q_0), find q:[0,T]→Rnq : [0, T] \to \mathbb{R}^n and λ:[0,T]→Rm\lambda : [0, T] \to \mathbb{R}^m with Mq¨=f−ΦqTλM \ddot q = f - \Phi_q^{\mathsf T} \lambda and Φ(q(t))=0\Phi(q(t)) = 0 for all tt. For the two-mass sketch, given ms,mu,ks,ktm_s, m_u, k_s, k_t, find the largest step hh at which RK4 on y˙=Ay\dot y = A y stays bounded.

Symbol In Meaning
t, Tt,\ T [0,T], (0,∞)[0, T],\ (0, \infty) time and the run's duration (s)
qq [0,T]→Rn[0, T] \to \mathbb{R}^n the pose coordinates: a position (m) and a unit quaternion per moving body
MM Rn×n\mathbb{R}^{n \times n} otkd's mass matrix (kg, and kg m² for rotations)
ff Rn\mathbb{R}^n the applied forces (N, and N m for moments)
Φ, Φq\Phi,\ \Phi_q Rn→Rm, Rm×n\mathbb{R}^n \to \mathbb{R}^m,\ \mathbb{R}^{m \times n} the rows, including the tyre's contact plane, and their Jacobian
λ\lambda [0,T]→Rm[0, T] \to \mathbb{R}^m the multipliers: the constraint forces
γ\gamma Rm\mathbb{R}^m the right side of Φqq¨=γ\Phi_q \ddot q = \gamma, from differentiating Φ=0\Phi = 0 twice
hh (0,∞)(0, \infty) the time step (s; the slider is in ms)
ms, mum_s,\ m_u (0,∞)(0, \infty) the sketch's chassis and unsprung masses (kg), from otkd
ks, ktk_s,\ k_t (0,∞)(0, \infty) the wheel rate, 25 kN/m, and the tyre rate on the slider (N/m)
M, KM,\ K R2×2\mathbb{R}^{2 \times 2} in the sketch only: diag⁡(ms,mu)\operatorname{diag}(m_s, m_u) (kg) and the stiffness matrix of ksk_s and ktk_t (N/m)
yy R4\mathbb{R}^4 the sketch's state: chassis and wheel displacements (m) and velocities (m/s)
AA R4×4\mathbb{R}^{4 \times 4} the first-order system matrix, y˙=Ay\dot y = A y
ωj, vj\omega_j,\ v_j (0,∞), R2(0, \infty),\ \mathbb{R}^2 the modes: Kvj=ωj2MvjK v_j = \omega_j^2 M v_j (rad/s); ωmax⁡\omega_{\max} is the largest
μ\mu C\mathbb{C} an eigenvalue of AA
RR C→C\mathbb{C} \to \mathbb{C} RK4's stability function: one step multiplies a mode by R(hμ)R(h\mu)
ν\nu R\mathbb{R} a real argument, R(iν)R(i\nu) on the imaginary axis
How these symbols connect

In otkd's moving corner, mass MM, applied forces ff and constraints Φ(q)=0\Phi(q) = 0 couple into Mq¨=f−ΦqTλM\ddot q = f - \Phi_q^{\mathsf T}\lambda over t∈[0,T]t \in [0, T]; differentiating Φ=0\Phi = 0 twice gives Φqq¨=γ\Phi_q\ddot q = \gamma so each RK4 stage solves a linear system for (q¨,λ)(\ddot q, \lambda). In the two-mass sketch, chassis and unsprung masses (ms,mu)(m_s, m_u) and spring rates (ks,kt)(k_s, k_t) build 2×22 \times 2 matrices M,KM, K (with modes ωj,vj\omega_j, v_j) and the first-order system y˙=Ay\dot y = A y (with eigenvalues μ\mu). Stepping with RK4 at step hh scales each eigenmode by R(hμ)R(h\mu), evaluated along the imaginary axis as R(iν)R(i\nu) to test boundedness.

Symbol-by-symbol notes
$M$ and $K$: full corner versus sketch

In the full DAE, M∈Rn×nM \in \mathbb{R}^{n \times n} is otkd's mass matrix (kg for translations, kg m2\text{kg m}^2 for rotations). In the two-mass sketch only, M=diag⁡(ms,mu)∈R2×2M = \operatorname{diag}(m_s, m_u) \in \mathbb{R}^{2 \times 2} and K∈R2×2K \in \mathbb{R}^{2 \times 2} are the 2-DOF mass and stiffness matrices (not §3's KKT matrix).

$\gamma$ in $\Phi_q \ddot q = \gamma$

Differentiating Φ(q(t))=0\Phi(q(t)) = 0 once gives Φqq˙=0\Phi_q \dot q = 0, and differentiating again gives Φqq¨+(Φqq˙)qq˙=0\Phi_q \ddot q + (\Phi_q \dot q)_q \dot q = 0. The vector γ=−(Φqq˙)qq˙∈Rm\gamma = -(\Phi_q \dot q)_q \dot q \in \mathbb{R}^m collects those velocity-dependent terms on the right-hand side.

$y$ and $A$

Stacking the chassis and wheel displacements (m) above their velocities (m/s) forms the state vector y∈R4y \in \mathbb{R}^4. Writing the second-order sketch in first-order form y˙=Ay\dot y = A y builds the 4×44 \times 4 matrix AA with −M−1K-M^{-1}K in its lower-left block and I2I_2 in its upper-right block.

$\omega_j$ versus $\mu$ and $\nu$

Each generalised eigenpair Kvj=ωj2MvjK v_j = \omega_j^2 M v_j gives a real angular frequency ωj>0\omega_j > 0 (rad/s) and mode shape vj∈R2v_j \in \mathbb{R}^2. For an undamped sketch the eigenvalues μ∈C\mu \in \mathbb{C} of AA are purely imaginary, and ν∈R\nu \in \mathbb{R} is the dimensionless argument when evaluating R(iν)R(i\nu).

$h$ (s versus ms) and $R$

The time step hh enters R(hμ)R(h\mu) in seconds so hμh\mu is dimensionless, while the interactive slider displays hh in milliseconds. R(z)R(z) is RK4's degree-4 polynomial stability function approximating eze^z.

Give the corner mass and release it. The equations become Mq¨=f−ΦqTλM\ddot q = f - \Phi_q^{\mathsf T}\lambda with Φ(q)=0\Phi(q) = 0: a differential-algebraic system, because the constraints have no time derivative of their own. otkd differentiates Φ=0\Phi = 0 twice, Φqq¨=γ\Phi_q \ddot q = \gamma, and solves the saddle-point system for (q¨,λ)(\ddot q, \lambda) at every stage of a classical RK4 step, then projects back onto the constraint. The class of each step is §3's; the class of the run is an initial-value problem.

The committed quarter-car run (books/maths-applied, 601 output steps over 3.0 s): the wheel travels from 0 to 212.8 mm and back, and first returns at t=0.625t = 0.625 s, about 1.6 Hz. With no damper it repeats. Energy drift over the run: 6.3e-08 of the start; largest constraint violation: 1.1e-15.

In that model the tyre is a hard row, a plane the wheel cannot leave. Write it instead as a spring and the class changes again: a second mode appears, the wheel hopping on the tyre. A two-mass sketch shows what it costs. The masses are otkd's: 300 kg of chassis, and 17.0 kg of arms and upright lumped at the wheel. The wheel rate ks=25k_s = 25 kN/m and the tyre rate ktk_t are chosen for the sketch, not taken from otkd. The modes solve Kv=ω2MvK v = \omega^2 M v (M05), and RK4 applied to y˙=Ay\dot y = A y multiplies each mode by R(hμ)R(h\mu) with R(z)=1+z+z2/2+z3/6+z4/24R(z) = 1 + z + z^2/2 + z^3/6 + z^4/24. For an undamped mode μ=iω\mu = i\omega and ∣R(iν)∣2=1−ν6/72+ν8/576|R(i\nu)|^2 = 1 - \nu^6/72 + \nu^8/576, which stays at or below 1 only while ν2≤8\nu^2 \le 8: stable for hω≤22h\omega \le 2\sqrt2, for every mode at once.

Figure 1

Predict first. Make the tyre ten times stiffer. The largest step at which RK4 stays stable

Choose a prediction

Check answer (without scripting)

Answer: shrinks about threefold, the square root of 10. The hop frequency is close to (ks+kt)/mu\sqrt{(k_s + k_t)/m_u}, so ten times ktk_t gives about 10≈3.2\sqrt{10} \approx 3.2 times ωmax⁡\omega_{\max} and a step that much smaller.

Reveal result (lock in your prediction above first)
bounce hop ratio
frequency (Hz) 1.37 18.3 13.4

Largest stable RK4 step: 24.60 ms; with the tyre ten times stiffer, 8.20 ms, smaller by 3.00. Accuracy for the bounce alone would allow far more. At your h=10h = 10 ms, hωmax⁡=1.15h\omega_{\max} = 1.15 against the limit 2.83: stable.

00.511.5210⁻²10⁻¹10⁰t (s)E(t) / E(0)

The wheel starts 20 mm displaced. Below the limit RK4 loses energy slowly; above it the hop mode grows by a fixed factor every step. As kt→∞k_t \to \infty the hop frequency goes with it and the explicit step goes to zero. otkd's rigid tyre is that limit taken exactly: the stiff mode is replaced by a constraint and a multiplier, and a 5 ms RK4 step only has the bounce to resolve. The other cure keeps the spring and goes implicit (M06).

When explicit time stepping breaks
  • Assumes: h ωmax⁡h\,\omega_{\max} lies inside the method's stability region for every mode
  • When it fails: a fast mode you do not care about grows without bound, and the run blows up at a step that is far finer than accuracy needs
  • Check: compute ωmax⁡\omega_{\max} from the eigenvalues before choosing hh; with no damping, watch the energy

5. Symptoms, and the diagnosis they point to

Setting: the problem, its sets and its symbols

Problem. Given rules F:R2→RℓF : \mathbb{R}^2 \to \mathbb{R}^\ell and the start p0p_0, find p∗∈R2p^* \in \mathbb{R}^2 with F(p∗)=0F(p^*) = 0, or the least-squares compromise when ℓ=3\ell = 3, by pk+1=pk−J~k+F(pk)p_{k+1} = p_k - \tilde J_k^{+} F(p_k). Then, from the residual history (ηk)(\eta_k) alone, find which fault was introduced.

Symbol In Meaning
pp R2\mathbb{R}^2 the upper ball joint in front view (m), as in §1
ci, ρic_i,\ \rho_i R2, (0,∞)\mathbb{R}^2,\ (0, \infty) §1's centres and radii (m); a third rule c3c_3, ρ3\rho_3 comes from otkd's point tri
ℓ\ell {2,3}\{2, 3\} the number of rules
FF R2→Rℓ\mathbb{R}^2 \to \mathbb{R}^\ell Fi(p)=∥p−ci∥2−ρi2F_i(p) = \lVert p - c_i \rVert^2 - \rho_i^2 (m²)
JFJ_F R2→Rℓ×2\mathbb{R}^2 \to \mathbb{R}^{\ell \times 2} the true Jacobian, with rows 2(p−ci)T2(p - c_i)^{\mathsf T}
J~k\tilde J_k Rℓ×2\mathbb{R}^{\ell \times 2} the matrix the iteration uses at step kk: JF(pk)J_F(p_k) when healthy, otherwise the fault's
A+A^{+} R2×ℓ\mathbb{R}^{2 \times \ell} the pseudo-inverse of AA: the least-squares solve
pkp_k R2\mathbb{R}^2 the iterates, from p0=(0.60,0.60)p_0 = (0.60, 0.60)
ηk\eta_k [0,∞)[0, \infty) the residual max⁡i∣Fi(pk)∣\max_i \lvert F_i(p_k) \rvert (m²); the readout is the ratio ηk+1/ηk\eta_{k+1}/\eta_k
faults\text{faults} one at a time\text{one at a time} J~k=JF(p0)\tilde J_k = J_F(p_0); J~k=12JF(pk)\tilde J_k = \tfrac12 J_F(p_k); ρ3\rho_3 1 mm too long; c2c_2 moved to put the two arms in line
How these symbols connect

The ℓ\ell circle rules F:R2→RℓF : \mathbb{R}^2 \to \mathbb{R}^\ell (ℓ=2\ell = 2 for the baseline corner, ℓ=3\ell = 3 when adding the third centre tri) have true Jacobian JF(p)J_F(p). Starting at p0=(0.60,0.60)p_0 = (0.60, 0.60), each step advances pk+1=pk−J~k+F(pk)p_{k+1} = p_k - \tilde J_k^{+} F(p_k) using the possibly faulted matrix J~k\tilde J_k and its pseudo-inverse A+A^{+}. Recording the max-norm residual ηk=max⁡i∣Fi(pk)∣\eta_k = \max_i \lvert F_i(p_k) \rvert and its step-to-step ratios ηk+1/ηk\eta_{k+1}/\eta_k produces a trace from which the active fault can be diagnosed.

Symbol-by-symbol notes
$J\lt em>F$ versus $\tilde J\lt /em>k$

JF(p)∈Rℓ×2J_F(p) \in \mathbb{R}^{\ell \times 2} is the exact Jacobian of FF at pp, with rows 2(p−ci)T2(p - c_i)^{\mathsf T}. J~k\tilde J_k is the matrix actually used at step kk: it equals JF(pk)J_F(p_k) in the healthy run and carries a single deliberate defect otherwise.

$A^{+}$ (the pseudo-inverse)

When ℓ=2\ell = 2 and J~k\tilde J_k is nonsingular, J~k+=J~k−1\tilde J_k^{+} = \tilde J_k^{-1} gives the ordinary Newton step. When ℓ=3\ell = 3 (over-determined) or J~k\tilde J_k loses rank, A+A^{+} computes the minimum-norm least-squares step (np.linalg.lstsq).

$\eta\lt em>k$ and the ratio $\eta\lt /em>{k+1}/\eta_k$

ηk=max⁡i∣Fi(pk)∣\eta_k = \max_i \lvert F_i(p_k) \rvert has units of m2\text{m}^2 because each FiF_i compares squared distances. The dimensionless ratio ηk+1/ηk\eta_{k+1}/\eta_k measures how the residual changes from one iteration to the next.

The four faults

Each fault alters one ingredient at a time: freezing J~k=JF(p0)\tilde J_k = J_F(p_0), dropping the factor of 22 so J~k=12JF(pk)\tilde J_k = \tfrac12 J_F(p_k), adding an inconsistent third rule (ℓ=3\ell = 3 with ρ3\rho_3 lengthened by 11 mm), or moving c2c_2 so the two circles are tangent (arms in line, a toggle).

A wrong solve has a shape, and the residual history is where it shows. The two-circle corner from §1, started from (0.60,0.60)(0.60, 0.60), with one fault at a time. Pick a fault, and predict first.

Predict first. Newton on the two circles, but the Jacobian is computed once at the starting guess and reused. How does the residual fall?

Choose a prediction

Check answer (without scripting)

Answer: by a roughly constant factor each step. The chord method converges linearly, at a rate set by how far J(q0)J(q_0) is from J(q∗)J(q^*). Close to the root it is cheap and slow; far away it may not converge.

Reveal result (lock in your prediction above first)
02.755.58.251110⁻¹⁷10⁻¹³10⁻⁹10⁻⁵10⁻¹healthyJacobian frozen at the startotheriterationmax |r| (m²)

Jacobian frozen at the start: successive residual ratios 0.042, 0.013, 0.011, 0.011, 0.011. A constant ratio well below 1 is linear convergence (the frozen Jacobian; the toggle, where the double root makes the ratio 1/4 in the residual). A ratio of 1 with alternating values is an overshoot. A ratio of 1 at a fixed level is a floor: least squares has found the best compromise between rules that disagree.

Symptoms, and the first suspect for each. The same reading extends past the residual to the rank, the time step and the energy.

what you see first suspect first check
the residual falls by a fixed factor per step an approximate or stale Jacobian; a singular one at the root the Jacobian against finite differences; rank at the answer
the residual alternates and never settles a step too large: a Jacobian wrong by a factor, or a fold the Jacobian by differences; damping or a line search
the residual stalls at a floor inconsistent rows, or the wrong model the residual row by row; the SVD's dependent rows
the rank drops a redundant row (left null space) or a lost constraint or toggle (right null space) which side of the SVD the zero is on
the time step collapses, or the run blows up a stiff mode and an explicit method the eigenvalues; an implicit method or a constraint
energy grows with no source a non-conservative scheme or a missing term halve hh: the drift must fall at the method's order
When reading a symptom breaks
  • Assumes: one fault at a time, so the residual history has one signature
  • When it fails: two faults together (a stale Jacobian near a toggle, say) give a mixed signature that looks like neither
  • Check: change one thing at a time: the Jacobian against finite differences first, then the rank at the answer, then the consistency of the rows

6. Is the answer right?

Setting: the problem, its sets and its symbols

Problem. Given A∈R2×2A \in \mathbb{R}^{2 \times 2}, b∈R2b \in \mathbb{R}^2 and a computed x^\hat x, bound the relative error ∥x^−x∥/∥x∥\lVert \hat x - x \rVert / \lVert x \rVert by quantities known without xx. Then, for the corner's own solves, find evidence that a computed answer is right when no exact solution is available.

Symbol In Meaning
aa [1,108][1, 10^8] the off-diagonal entry (log⁡10a\log_{10} a on the slider)
AA R2×2\mathbb{R}^{2 \times 2} the matrix with rows (1,a)(1, a) and (0,1)(0, 1)
bb R2\mathbb{R}^2 the right side (a,1)(a, 1); its second entry is perturbed by 10−1010^{-10} before the solve
x, x^x,\ \hat x R2\mathbb{R}^2 the exact solution (0,1)(0, 1) and the computed one
rr R2\mathbb{R}^2 the residual b−Ax^b - A\hat x, against the unperturbed bb
∥⋅∥\lVert \cdot \rVert R2→[0,∞)\mathbb{R}^2 \to [0, \infty) a vector norm and the matrix norm it induces
κ(A)\kappa(A) [1,∞)[1, \infty) the condition number ∥A∥ ∥A−1∥\lVert A \rVert\,\lVert A^{-1} \rVert; the table uses the ∞\infty-norm
J, κ(J)J,\ \kappa(J) Rm×n, [1,∞)\mathbb{R}^{m \times n},\ [1, \infty) §1's Jacobian at the answer and its condition number
c, g, g/cc,\ g,\ g/c (0,∞), R, R(0, \infty),\ \mathbb{R},\ \mathbb{R} §3's tie-rod compliance (m/N), extension (m) and force (N)
hh (0,∞)(0, \infty) the RK4 step on §4's sketch (s)
EE [0,T]→[0,∞)[0, T] \to [0, \infty) the sketch's energy (J), conserved by the exact motion
order\text{order} R\mathbb{R} log⁡2\log_2 of the ratio of successive errors as hh halves
How these symbols connect

For the 2×22 \times 2 linear system Ax=bAx = b parameterised by aa, perturbing b2b_2 by 10−1010^{-10} gives a computed vector x^\hat x whose residual r=b−Ax^r = b - A\hat x and condition number κ(A)=∥A∥ ∥A−1∥\kappa(A) = \lVert A \rVert\,\lVert A^{-1} \rVert bound the unknown relative error ∥x^−x∥/∥x∥\lVert \hat x - x \rVert / \lVert x \rVert without needing xx. The same verification discipline extends to the corner's own solves: pairing §1's residual with κ(J)\kappa(J), checking §3's tie-rod force g/cg/c as compliance c→0c \to 0, and tracking §4's conserved energy EE and empirical order\text{order} as RK4's step hh halves.

Symbol-by-symbol notes
$r$ versus $\hat x - x$

The residual r=b−Ax^r = b - A\hat x measures how well x^\hat x satisfies the equation (always computable), whereas x^−x\hat x - x measures how close x^\hat x is to the exact solution (unknown in practice). They are linked by x−x^=A−1rx - \hat x = A^{-1} r, which is where κ(A)\kappa(A) enters.

$\lVert \cdot \rVert$ and $\kappa(A)$

The error bound holds for any vector norm paired with its induced matrix norm ∥A∥=max⁡v≠0∥Av∥/∥v∥\lVert A \rVert = \max_{v \ne 0} \lVert A v \rVert / \lVert v \rVert. The interactive table uses the ∞\infty-norm (maximum absolute entry for vectors, maximum absolute row sum for matrices), giving κ∞(A)=∥A∥∞∥A−1∥∞≥1\kappa_\infty(A) = \lVert A \rVert_\infty \lVert A^{-1} \rVert_\infty \ge 1.

$c$, $g$ and $g/c$

In §3's compliant corner, as tie-rod compliance c→0c \to 0 (m/N\text{m/N}), the extension gg (m) shrinks towards zero while their ratio g/cg/c (N) is the elastic tie-rod force approaching the rigid reaction.

$E$ and $\text{order}$

Along the exact undamped motion of §4's sketch, mechanical energy E(t)E(t) (J) is constant, so ∣E(T)/E(0)−1∣\lvert E(T)/E(0) - 1 \rvert checks accuracy without a reference solution. Halving hh computes the empirical order=log⁡2(errorh/errorh/2)\text{order} = \log_2(\text{error}_h / \text{error}_{h/2}) separately for position and for energy.

A residual measures the equation; an error measures the answer. For Ax=bAx = b with computed x^\hat x and residual r=b−Ax^r = b - A\hat x, x−x^=A−1rx - \hat x = A^{-1} r, so

∥x^−x∥∥x∥≤κ(A) ∥r∥∥b∥.\frac{\|\hat x - x\|}{\|x\|} \le \kappa(A)\, \frac{\|r\|}{\|b\|}.

The book's check: A=[1a01]A = \begin{bmatrix} 1 & a \\ 0 & 1 \end{bmatrix}, b=(a,1)b = (a, 1), exact x=(0,1)x = (0, 1), and b2b_2 perturbed by 10−1010^{-10}. Move aa.

κ∞(A)\kappa_\infty(A) relative residual relative error bound κ⋅\kappa \cdot residual
1.0e+06 1.0e-13 1.0e-07 1.0e-07

The residual shrinks as aa grows while the error does not: at large κ\kappa a tiny residual certifies nothing until the conditioning is multiplied in.

Four checks on the corner, none of which needs the exact answer.

1. The residual, with the conditioning. §1's Newton ends at 3.2e-16 with κ(J)=47\kappa(J) = 47: an error estimate near 1e-14 in coordinates of order 1.

2. A second, independent method. otkd's closed-form two-circle camber against the Newton sweep: largest difference 2e-13 degrees over 81 frames. Least squares on the two-leg model against Newton with the spare row dropped: 9.1e-16. Two runs of the same code would not count: they share their mistakes.

3. A limit case that returns a trusted model. Stiffen the compliant tie rod towards rigid (otkd's equilibrium solver, at rest, under the study's loads). The extension goes to zero and the force converges, each decade changing it about ten times less than the last: first order in cc, the §3 penalty again.

compliance (m/N) tie-rod extension (m) tie-rod force g/c (N) change from previous (N)
1e-05 -1.778e-04 -17.7801
1e-06 -1.880e-05 -18.7956 -1.0155
1e-07 -1.890e-06 -18.9035 -0.1079
1e-08 -1.891e-07 -18.9144 -0.0109
1e-09 -1.892e-08 -18.9155 -0.0011

4. A conserved quantity, and a convergence table. With no damper the energy is conserved, so its drift is a check with no reference solution: the committed quarter-car run drifts by 6.3e-08. On the §4 sketch (tyre 2×1052 \times 10^5 N/m, one second, against the exact solution from the matrix exponential), halving hh:

h (ms) position error order energy error energy order
8 9.05e-03 6.13e-01
4 8.52e-04 3.41 3.17e-02 4.27
2 5.24e-05 4.02 1.03e-03 4.95
1 3.19e-06 4.04 3.22e-05 4.99

The position settles at order 4, RK4's order. The energy error settles near 5, one higher: per step 1−∣R(ihω)∣2=(hω)6/72+…1 - |R(i h\omega)|^2 = (h\omega)^6/72 + \dots, and 1/h1/h steps give h5h^5. A convergence table checks the order of the quantity you measure.

When a small residual as evidence breaks
  • Assumes: the problem is well conditioned and the equations are the ones you meant
  • When it fails: the conditioning multiplies the residual into the error, and a converged answer to the wrong model looks exactly like a right one
  • Check: κ\kappa times the relative residual, an independent second method, a limit case that returns a trusted model, and a conserved quantity

Practice

Practice A (steps partly filled). Replace the constraint x=1x = 1 in min⁡12x2−2x\min \tfrac12 x^2 - 2x by a spring of stiffness kk. Stationarity of 12x2−2x+k2(x−1)2\tfrac12 x^2 - 2x + \tfrac{k}{2}(x-1)^2 gives xk=(2+k)/(1+k)x_k = (2+k)/(1+k), so the constraint error is xk−1=1/(1+k)x_k - 1 = 1/(1+k). For an error of at most 10−310^{-3}: 1+k≥  ?1 + k \ge \;? Enter the smallest kk.

Worked solution

1/(1+k)≤10−3⇒1+k≥1000⇒k≥9991/(1+k) \le 10^{-3} \Rightarrow 1 + k \ge 1000 \Rightarrow k \ge 999. The penalty force k(xk−1)=k/(1+k)k(x_k - 1) = k/(1+k) is then 0.9990.999, against the KKT multiplier λ=1\lambda = 1 that the saddle-point solve gives exactly.

Practice B (with a hint). A wheel of 17 kg on a tyre of 2×1052 \times 10^5 N/m and a suspension of 2.5×1042.5 \times 10^4 N/m. Estimate the largest stable RK4 step, in milliseconds, from the wheel alone.

Worked solution

ω≈2.25×105/17=115.0\omega \approx \sqrt{2.25 \times 10^5 / 17} = 115.0 rad/s, so h≤22/ω=24.6h \le 2\sqrt2/\omega = 24.6 ms. The coupled two-mass value in §4 is within a few per cent: the body barely moves in the hop mode.

Hint 1

Treat the body as fixed: the wheel sits between two springs in parallel, so ω≈(ks+kt)/mu\omega \approx \sqrt{(k_s + k_t)/m_u}.

Hint 2

RK4 on an undamped mode is stable for hω≤22h\omega \le 2\sqrt 2.

Practice C (on your own). A solve reports a relative residual of 10−1410^{-14}, and the matrix has κ=108\kappa = 10^8. Enter log⁡10\log_{10} of the bound on the relative error.

Worked solution

κ⋅∥r∥/∥b∥=108×10−14=10−6\kappa \cdot \|r\|/\|b\| = 10^8 \times 10^{-14} = 10^{-6}, so −6-6: six digits you may trust, not fourteen.

Mixed practice: which class, which method, and why?

Name the class before you pick an option.

1. A four-bar linkage's output angle at a given crank angle. Which class, and which method?

Question 1
How sure?

2. Fit a three-parameter tyre curve to 200 measured points. Which class, and which method?

Question 2
How sure?

3. A heat equation in a damper's oil, with a fine mesh. Which class, and which method?

Question 3
How sure?

4. The body-bounce and wheel-hop frequencies of a quarter car. Which class, and which method?

Question 4
How sure?

5. A new integrator's order, with no exact solution available. What do you compute?

Question 5
How sure?

6. How far the camber at rest spreads when every pivot is placed to within 0.5 mm. Which class, and which method?

Question 6
How sure?

Show answers and explanations

1. A square nonlinear system: Newton, from the last solved position. Two loop-closure rules, two unknown angles, full rank away from a toggle. Seeding from the last frame keeps the same assembly (M02).

2. Over-determined and inconsistent: least squares, and read the residual. The residual floor is the measurement noise and the model error; it is the answer, not a fault (M03).

3. A stiff initial-value problem: an implicit time stepper. The fastest diffusion mode scales like 1/Δx21/\Delta x^2; an explicit step would be set by it, not by the accuracy you need (M06).

4. A generalised eigenvalue problem, K v = w^2 M v. Linearise about the rest position, then the modes are the eigenpairs of (K,M)(K, M) (M05). §4 did exactly this.

5. Runs at h, h/2 and h/4, and the observed order from successive differences. Richardson's ratio gives the order with no exact answer (M01), and §6's table is the same check against an exact one.

6. Averaging: sample the pivots, solve each corner, report the spread with an error bar. A spread over uncertain inputs is an average; Monte Carlo's error falls like 1/N1/\sqrt N whatever the dimension (M07). Each sample is still a §1 Newton solve.

Check yourself (closed book)

1. A corner model has 22 rows and 21 unknowns, and all 22 rows together have rank 21. Which solve fits, and why?

Question 1
How sure?

2. The two-leg corner's Jacobian is 22×2122 \times 21 with rank 21. Where does its redundancy show?

Question 2
How sure?

3. The compliant corner's KKT matrix has blocks HH and BTB^{\mathsf T} over BB and 00, with 21 unknowns and 20 constraint rows. Why not use Cholesky or conjugate gradients on it?

Question 3
How sure?

4. You replace a rigid joint with a spring of stiffness kk to avoid the saddle point. As kk grows,

Question 4
How sure?

5. A quarter car with a tyre spring has a body bounce near 1.4 Hz and a wheel hop near 18 Hz. You want the bounce. What limits an explicit step size?

Question 5
How sure?

6. Newton's residual alternates between two values and never falls. The most likely cause?

Question 6
How sure?

7. A linear solve reports a relative residual of 10−1310^{-13}, and κ(A)=106\kappa(A) = 10^6. What can you say about the relative error?

Question 7
How sure?

8. Which second answer is real evidence that the rigid corner's Newton sweep is right?

Question 8
How sure?

Show answers and explanations

1. Least squares, then an SVD to name the redundant row. Rows minus rank is 1, so one row is redundant. Least squares solves the consistent over-determined system; the SVD's left null space says which rows depend on each other.

2. In the left null space: a combination of rows that sums to zero. A vector uu with uTJ=0u^{\mathsf T} J = 0 is a dependence among rows. Its support names the rows that say the same thing.

3. It is symmetric but indefinite, with one negative eigenvalue per constraint row. With BB of full row rank and HH positive on the null space of BB, the inertia is 21 positive and 20 negative. Cholesky and CG need positive definiteness.

4. the constraint error falls like 1/k and the condition number grows like k. That is the trade: accuracy in the rule costs conditioning in the solve. The KKT form is exact at a fixed condition number, and pays with indefiniteness instead.

5. The wheel hop, even though you do not need it. An explicit method must keep hωh\omega inside its stability region for every mode. The fast mode sets hh; that is what stiffness means.

6. A Jacobian wrong by a constant factor, so each step overshoots. With J/2J/2 in place of JJ every step is twice the Newton step and lands as far past the root as it started. Check the Jacobian by finite differences.

7. At most about 1e-7. κ⋅∥r∥/∥b∥=106×10−13=10−7\kappa \cdot \|r\| / \|b\| = 10^6 \times 10^{-13} = 10^{-7}. A small residual is evidence only after the conditioning has been multiplied in.

8. The closed-form two-circle solution, compared frame by frame. An independent derivation shares none of Newton's code or rows. otkd's agreement between the two is 2×10−132 \times 10^{-13} degrees of camber.

Keep these:

  1. The class is a property of how the model is written: rows, unknowns and rank decide it, and the solve follows.
  2. Square and full rank: Newton. Rows above rank, rank nn: least squares, then the left null space names the spare rows.
  3. A constraint with a price is a KKT saddle point, indefinite with one negative eigenvalue per row; a penalty is definite, approximate to 1/k1/k and conditioned like kk.
  4. An explicit step is set by the fastest mode; a stiff spring can be replaced by a constraint, or kept and stepped implicitly.
  5. Read the residual history: linear, alternating, a floor, a rank drop. Then check the answer with κ⋅\kappa \cdot residual, a second method, a limit case and a conserved quantity.

Your connection

Pick a model you work with. Write down its class as you posed it, one other way you could have posed it, and which check would tell you the two agree.

Answers

Practice A. k≥999k \ge 999.

Practice B. about 24.6 ms, from ω≈115\omega \approx 115 rad/s.

Practice C. −6-6.

Mixed practice. Newton; least squares; implicit time stepping; a generalised eigenproblem; a convergence table from three runs; Monte Carlo with an error bar.

Where the maths is derived

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

§1 A square system: Newton

§2 A spare row: least squares and the SVD

§3 A compliant joint: the KKT saddle point

§4 A moving corner: stiffness and modes

§6 Is the answer right?


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

Back to the book: The same corner, five ways · The class is a choice

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.