Maths Applied1.6

All books

S07 — Mass and dampers

§1.2 to §1.5 asked where the wheel is. §1.6 asks what it does: release the corner and it swings. That needs mass, and mass turns a set of algebraic constraints into a differential–algebraic equation. The model is otkd's examples/quarter-car: a chassis on a vertical slide, the double-wishbone corner hung from it, a coil-over that is a spring with no damper, and the tyre held on a road plane. This notebook asks how otkd integrates it, how to tell the integration is right, what the energy test cannot see, and what a damper would add.

Book page: §1.6 Mass and dampers, Walkthrough, in books/maths-applied. The quarter-car numbers are otkd's own: the committed 3 s run the book draws, and live runs on the same model files, cached after the first.

The question. Released from its design pose, the quarter car swings for ever. How does otkd integrate a linkage with mass so that it stays a linkage, how do you know the integration is right, and what would a damper change?

By the end you can:

  • write a mechanism as Mq¨=f−ΦqTλM\ddot q = f - \Phi_q^{\mathsf T}\lambda, Φ(q)=0\Phi(q) = 0, and check that a multiplier is a force
  • reduce the index to the acceleration level, solve the saddle-point system, and say why the reduced system drifts
  • measure the order of RK4's energy error on the real model, and say why projection keeps the constraint at round-off
  • say what an energy test cannot detect, with otkd's unrotated inertia tensor as the example
  • predict a damped quarter car's modes, overshoot and settling, and say why §1.6 leaves the damper out

Assumes: M01 (order), M05 (modes), M06 (time stepping and stability), M08 §3–§4 (the KKT saddle point; the moving corner).

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: otkd integrates the quarter car with classical RK4, order 4, and projects onto the constraints after every step. On M08's linear two-mass sketch, halving the step divided RK4's energy error by about 32. On the quarter car itself, halving the step divides the energy drift over the first 0.2 s by about

Choose a prediction

Check answer (without scripting)

Answer: 16, the method's own order. Order 4: the local error has a part across the energy surface, so the energy carries the method's order. The run without projection shows the same, so the projection is not the cause.

Warm-up: remember

1. A compliant model is solved with no load at a ladder of stiffnesses, and every rung matches the rigid answer exactly. What does that show?

Question 1
How sure?

2. otkd's branch_changed flag compares each frame's solution with

Question 2
How sure?

3. otkd's least_squares passes no Jacobian to SciPy. What does that cost on the 21-unknown corner?

Question 3
How sure?

Show answers and explanations

1. Nothing: with no load every deflection is zero at any stiffness. Stationarity gives g=0g = 0 when F=0F = 0, so the ladder is flat. A limit test needs a load, and a deflection you can see.

2. its seed, the previous frame, against 0.25 rad and 0.05 m per body. Any body that turned more than 0.25 rad or moved more than 0.05 m since the seed raises the flag. It is recorded, never raised as an error.

3. About 21 extra residual calls per Jacobian, and a Jacobian good to about 8 digits. Forward differences cost nn calls and have error near ϵ\sqrt{\epsilon}. Here the solve made 116 residual calls for 5 counted evaluations, and still reached round-off.

1. A linkage with mass

Setting: the problem, its sets and its symbols

Problem. Given the moving bodies B\mathcal B, the constraint map Φ\Phi, the mass matrix MM, the forces ff and the design pose q0q_0, find q:[0,tf]→Rnq : [0, t_f] \to \mathbb R^n and λ:[0,tf]→Rm\lambda : [0, t_f] \to \mathbb R^m such that M(q)q¨+C(q,q˙)=f(q,q˙)−Φq(q)TλM(q)\ddot q + C(q, \dot q) = f(q, \dot q) - \Phi_q(q)^{\mathsf T}\lambda and Φ(q)=0\Phi(q) = 0 for every t∈[0,tf]t \in [0, t_f], with q(0)=q0q(0) = q_0 and q˙(0)=0\dot q(0) = 0. The data are B,Φ,M,f,q0\mathcal B, \Phi, M, f, q_0; the unknowns are qq and λ\lambda.

Symbol In Meaning
B\mathcal B {chassis,lca,uca,up}\{\text{chassis}, \text{lca}, \text{uca}, \text{up}\} the moving bodies; the ground is fixed
bb B\mathcal B one body
nn N\mathbb N number of pose coordinates, seven per body
mm N\mathbb N number of constraint rows: joint rows, the road contact, one quaternion norm per body
t, tft,\ t_f [0,tf]⊂R[0, t_f] \subset \mathbb R time and the end of the run (s); the committed run has tft_f = 3 s
q(t)q(t) Rn\mathbb R^{n} the poses: per body a position (m) and a unit quaternion (dimensionless)
q˙, q¨\dot q,\ \ddot q Rn\mathbb R^{n} their first and second time derivatives (per s, per s²)
q0q_0 Rn\mathbb R^{n} the design pose: positions zero, quaternions the identity
Φ\Phi Rn→Rm\mathbb R^{n} \to \mathbb R^{m} the constraint map (m for a length row, dimensionless for an angle or norm row)
Φq(q)\Phi_q(q) Rm×n\mathbb R^{m \times n} its Jacobian
M(q)M(q) Rn×n\mathbb R^{n \times n} the mass matrix, symmetric (kg, kg m²)
C(q,q˙)C(q, \dot q) Rn\mathbb R^{n} the velocity-product term a pose-dependent MM brings (generalised force: N, N m)
f(q,q˙)f(q, \dot q) Rn\mathbb R^{n} gravity and the coil spring, as a generalised force (N, N m)
cc R>0\mathbb R_{>0} the coil's compliance, 10⁻⁵ m/N; the coil row is a force, not a constraint
λ(t)\lambda(t) Rm\mathbb R^{m} the multipliers: each row's reaction (N for a length row)
s(t), θc(t)s(t),\ \theta_c(t) R\mathbb R wheel travel relative to the chassis (mm, positive in bump) and camber (degrees, otkd's sign)
How these symbols connect

Each moving body in B\mathcal B contributes seven coordinates to q(t)∈Rnq(t) \in \mathbb R^n, and the constraint map Φ:Rn→Rm\Phi : \mathbb R^n \to \mathbb R^m restricts q(t)q(t) to the poses the joints, road contact and unit-quaternion norms allow. The applied forces f(q,q˙)f(q, \dot q) (gravity and the compliant coil of compliance cc) and the constraint reactions −Φq(q)Tλ(t)-\Phi_q(q)^{\mathsf T}\lambda(t) drive M(q)q¨+C(q,q˙)M(q)\ddot q + C(q, \dot q) over t∈[0,tf]t \in [0, t_f] from rest at q0q_0. Because qq mixes metres with dimensionless quaternion entries and Φ\Phi mixes lengths with dimensionless rows, every product ΦqTλ\Phi_q^{\mathsf T}\lambda pairs each multiplier's units with its row's units to give generalised forces in N and N m; from q(t)q(t), the kinematic readouts s(t)s(t) (mm) and θc(t)\theta_c(t) (degrees) report the wheel motion.

Symbol-by-symbol notes
$q(t)$ and $q_0$ — mixed-unit pose vector

Each body b∈Bb \in \mathcal B occupies a seven-entry slice: three translational coordinates in m followed by four dimensionless unit-quaternion components. At q0q_0 every translation is zero and every quaternion is the identity (1,0,0,0)(1, 0, 0, 0), so the mechanism starts in its design pose with Φ(q0)=0\Phi(q_0) = 0.

$M(q)$ and $C(q, \dot q)$ — configuration-dependent inertia

Because a body's orientation changes with qq, its rotational block in M(q)M(q) depends on the pose. Differentiating M(q)q˙M(q)\dot q in time produces both M(q)q¨M(q)\ddot q and the velocity-product vector C(q,q˙)C(q, \dot q), which is quadratic in q˙\dot q and vanishes at rest (q˙=0\dot q = 0).

$\Phi$, $\Phi_q$ and $\lambda$ — constraints versus spring rows

The mm rows of Φ\Phi hold only the hard joint constraints, the road contact and the quaternion norms; the coil spring is excluded from Φ\Phi and enters ff through its compliance cc. Each multiplier λi\lambda_i has units of energy per unit of row Φi\Phi_i (N for a length row in m, N m for a dimensionless angle or norm row), so ΦqTλ\Phi_q^{\mathsf T}\lambda always lands in generalised-force units.

$c$ — compliance, not stiffness

Compliance is the reciprocal of spring rate, measured in m/N rather than N/m. A compliance of 10−5 m/N10^{-5}\text{ m/N} corresponds to a coil stiffness of 1/c=105 N/m1/c = 10^5\text{ N/m} (100 kN/m).

$s(t)$ and $\theta_c(t)$ — sign conventions

Wheel travel s(t)s(t) is measured in mm relative to the chassis, positive into bump (the wheel moving up towards the body). Camber θc(t)\theta_c(t) uses otkd's sign convention, positive when the top of the wheel leans inboard.

Start with what the book draws. otkd releases the quarter car from its design pose, at rest, with only gravity acting: the coil carries no load at that pose, so the chassis falls, the coil compresses, and the wheel travels from 0 to 212.8 mm into bump and back, once every 0.625 s (1.60 Hz). Camber goes from 0 to -9.53° (otkd's sign, and the book's: positive with the top of the wheel outboard). There is no damper, so it repeats for the whole 3 s.

The unknowns and the rows. otkd gives each of the 4 moving bodies a pose of seven numbers (a position and a unit quaternion), so qq has n=28n = 28 entries. The joints give 23 hard rows (the contact with the road is one of them) and the quaternions 4 norm rows: m=27m = 27 constraints Φ(q)=0\Phi(q) = 0. The coil is a spring row: a force, not a constraint. So the mechanism has n−m=1n - m = 1 freedom (otkd's check: mobility 1, redundancy 0), the heave of the chassis with everything else following it.

The equations. Lagrange's equations with multipliers: each constraint row ii exerts a force along its own gradient, with an unknown size λi\lambda_i,

M(q) q¨+C(q,q˙)=f(q,q˙)−Φq(q)Tλ,Φ(q)=0.M(q)\,\ddot q + C(q, \dot q) = f(q, \dot q) - \Phi_q(q)^{\mathsf T}\lambda, \qquad \Phi(q) = 0 .

MM is the mass matrix, CC the velocity-product term a configuration-dependent MM brings, ff gravity and the coil, and ΦqTλ\Phi_q^{\mathsf T}\lambda the forces that keep the arms, the joints and the tyre on their rows. Differential equations for qq, algebraic ones for the pose: a differential–algebraic equation. Move the slider through the committed run.

00.751.52.253-12.846.8106166226t (s)travel (mm)
00.751.52.253-10.1-7.43-4.76-2.10.572t (s)camber (°)

At tt = 0.300 s: travel 211.8 mm, camber -9.450°, chassis heave -211.8 mm. With one freedom, camber is a function of travel alone, so the two curves keep step.

2. Index reduction: from Φ(q)=0\Phi(q) = 0 to one linear solve

Setting: the problem, its sets and its symbols

Problem. Given a state (q,q˙)∈Rn×Rn(q, \dot q) \in \mathbb R^n \times \mathbb R^n with Φ(q)=0\Phi(q) = 0 and Φqq˙=0\Phi_q\dot q = 0, find (q¨,λ)∈Rn×Rm(\ddot q, \lambda) \in \mathbb R^n \times \mathbb R^m such that Mq¨+ΦqTλ=f−CM\ddot q + \Phi_q^{\mathsf T}\lambda = f - C and Φqq¨=γ\Phi_q\ddot q = \gamma. Then, for a step hh, integrate (q,q˙)(q, \dot q) with RK4 on these accelerations over [0,0.2][0, 0.2] s, with and without projection, and record the residual r(t)r(t).

Symbol In Meaning
B, b\mathcal B,\ b {chassis,lca,uca,up}\{\text{chassis}, \text{lca}, \text{uca}, \text{up}\} the moving bodies, and one of them
n, mn,\ m N\mathbb N pose coordinates (seven per body) and constraint rows
q, q˙, q¨q,\ \dot q,\ \ddot q Rn\mathbb R^{n} pose (m; quaternions dimensionless), its velocity and acceleration
Φ, Φq\Phi,\ \Phi_q Rn→Rm, Rm×n\mathbb R^{n} \to \mathbb R^{m},\ \mathbb R^{m \times n} the constraint map and its Jacobian
M, C, fM,\ C,\ f Rn×n, Rn, Rn\mathbb R^{n \times n},\ \mathbb R^{n},\ \mathbb R^{n} mass matrix (kg, kg m²), velocity-product term and applied force (N, N m)
γ(q,q˙)\gamma(q, \dot q) Rm\mathbb R^{m} −(Φqq˙)q q˙-(\Phi_q\dot q)_q\,\dot q, the right side at acceleration level (m/s² for a length row)
λ\lambda Rm\mathbb R^{m} the multipliers, unknown with q¨\ddot q (N for a length row)
KK R(n+m)×(n+m)\mathbb R^{(n+m) \times (n+m)} the saddle-point matrix, symmetric
mb, ab,zm_b,\ a_{b,z} R>0, R\mathbb R_{>0},\ \mathbb R body bb's mass (kg) and its centre of mass's vertical acceleration (m/s²)
WW R>0\mathbb R_{>0} the car's weight, g∑bmbg \sum_b m_b (N)
hh {0.02,0.01,0.005}\{0.02, 0.01, 0.005\} the RK4 step (s)
r(t)r(t) R≥0\mathbb R_{\ge 0} ∥Φ(q(t))∥∞\lVert \Phi(q(t)) \rVert_\infty, the largest residual (m for a length row, dimensionless for a norm)
How these symbols connect

At any admissible state (q,q˙)(q, \dot q) with Φ(q)=0\Phi(q) = 0 and Φqq˙=0\Phi_q\dot q = 0, differentiating the constraints twice yields Φqq¨=γ(q,q˙)\Phi_q\ddot q = \gamma(q, \dot q) and stacks with the equations of motion into the (n+m)×(n+m)(n + m) \times (n + m) linear system K[q¨; λ]=[f−C; γ]K[\ddot q;\ \lambda] = [f - C;\ \gamma]. Solving for (q¨,λ)(\ddot q, \lambda) supplies the acceleration field that RK4 integrates at step size hh, while λ\lambda simultaneously returns the reactions checked against the vertical force balance W+∑bmbab,zW + \sum_b m_b a_{b,z}. Monitoring r(t)=∥Φ(q(t))∥∞r(t) = \lVert \Phi(q(t)) \rVert_\infty along the unprojected and projected runs tests how closely the numerical trajectory stays on Φ(q)=0\Phi(q) = 0.

Symbol-by-symbol notes
$\gamma(q, \dot q)$ — acceleration-level right-hand side

Differentiating Φq(q)q˙=0\Phi_q(q)\dot q = 0 once more in time gives Φqq¨+(Φqq˙)qq˙=0\Phi_q\ddot q + (\Phi_q\dot q)_q\dot q = 0, so γ=−(Φqq˙)qq˙\gamma = -(\Phi_q\dot q)_q\dot q is quadratic in q˙\dot q and vanishes at rest. Its units match Φ¨\ddot\Phi (m/s² on a length row, s−2^{-2} on a dimensionless row).

$K$ — the saddle-point matrix

Assembled as the block matrix [MΦqTΦq0]\begin{bmatrix} M & \Phi_q^{\mathsf T} \\ \Phi_q & 0 \end{bmatrix}, KK is symmetric and indefinite because its lower-right m×mm \times m block is zero. It is nonsingular whenever Φq\Phi_q has full row rank and MM is positive definite on the tangent space ker⁡(Φq)\ker(\Phi_q).

$W$, $m\lt em>b$ and $a\lt /em>{b,z}$ — independent force-balance check

Here W=g∑b∈BmbW = g\sum_{b \in \mathcal B} m_b is the total weight of all moving bodies (positive in N) and ab,za_{b,z} is the vertical component of body bb's centre-of-mass acceleration computed from q¨\ddot q. Summing W+∑bmbab,zW + \sum_b m_b a_{b,z} uses only Newton's second law for the whole car, providing an external check on the road-contact multiplier.

$r(t)$ — max-norm constraint residual

Defined as max⁡i∣Φi(q(t))∣\max_i \lvert \Phi_i(q(t)) \rvert, the infinity norm combines length rows (m) and dimensionless angle or quaternion-norm rows into one non-negative scalar. Comparing r(t)r(t) across h∈{0.02,0.01,0.005}h \in \{0.02, 0.01, 0.005\} s tracks how the constraint residual responds to step refinement.

$\lambda$ — sign of a reaction multiplier

Because the equations of motion carry −ΦqTλ-\Phi_q^{\mathsf T}\lambda, the sign of λi\lambda_i depends on the direction in which row Φi\Phi_i increases. A negative value on a contact row means the reaction pushes against the gradient ∇Φi\nabla\Phi_i.

The DAE cannot go to an ODE solver as it stands: Φ(q)=0\Phi(q) = 0 contains neither q¨\ddot q nor λ\lambda, so nothing fixes λ\lambda. Differentiate the constraint along the motion. Once: Φqq˙=0\Phi_q\dot q = 0, the velocity must be tangent to the constraint. Twice:

Φqq¨+(Φqq˙)q q˙=0⟹Φqq¨=γ,γ=−(Φqq˙)q q˙.\Phi_q\ddot q + \big(\Phi_q\dot q\big)_q\,\dot q = 0 \quad\Longrightarrow\quad \Phi_q\ddot q = \gamma, \qquad \gamma = -\big(\Phi_q\dot q\big)_q\,\dot q .

Now stack it with the dynamics. At each state, q¨\ddot q and λ\lambda solve one symmetric saddle-point system (M08 §3's KKT shape, with MM in place of the Hessian):

[MΦqTΦq0][q¨λ]=[f−Cγ].\begin{bmatrix} M & \Phi_q^{\mathsf T} \\ \Phi_q & 0 \end{bmatrix} \begin{bmatrix} \ddot q \\ \lambda \end{bmatrix} = \begin{bmatrix} f - C \\ \gamma \end{bmatrix} .

Two differentiations gave an equation for q¨\ddot q that, with the dynamics, fixes λ\lambda algebraically; a third would give λ˙\dot\lambda. The original system has index 3, the reduced one index 1, and an ODE solver can integrate (q,q˙)(q, \dot q) with q¨\ddot q from this solve. otkd builds γ\gamma without a Hessian: two Jacobian evaluations, a central difference along q˙\dot q.

The multiplier is a force. At the design pose the saddle matrix (n+m=n + m = 55) has 28 positive and 27 negative eigenvalues, one negative per constraint (condition number 3.1e+06). At release the contact row's multiplier is λ = -139.00. Check it with nothing but Newton's second law for the whole car: the only vertical external forces are gravity and the road (the chassis slide carries no vertical force), so the road pushes up with W+∑bmbab,zW + \sum_b m_b a_{b,z} = 139.00 N, where WW = 3109.8 N and ab,za_{b,z} is each body's centre-of-mass acceleration from the same solve. The two agree: λ\lambda is the contact force in newtons, negative because the row's gradient points into the road.

00.160.320.480.64-0.6742.475.618.7611.9road on the tyre, -λcoil, compressiont (s)force (kN)

Along a 20 ms run of the same model: the load at the contact patch is something the motion produces, not an input. It peaks at 6684 N at the far end of the swing, 2.15 times the car's weight, and the coil at 11228 N.

source: `open_textbook.otkd.problem.dynamics.accelerations` — `solvers/otkd/src/open_textbook/otkd/problem/dynamics.py:259`
def accelerations(
    problem: Problem,
    q: np.ndarray,
    qdot: np.ndarray,
    *,
    loads: list[tuple[str, str, np.ndarray]] | None = None,
    gravity: np.ndarray | None = None,
    theta: np.ndarray | None = None,
) -> Accelerations:
    """Solve the saddle-point system for the acceleration and every reaction."""
    g = problem.numbers()
    theta = problem.theta0() if theta is None else theta
    rows = [i for i, row in enumerate(problem.rows) if row.group != SPRING]
    mass = mass_matrix(problem, q, g)
    force = forces(problem, q, qdot, g, theta, loads, gravity)
    force = force - velocity_products(problem, q, qdot, g)
    constraint, gamma = acceleration_terms(problem, q, qdot, g, theta)

    size = problem.n + len(rows)
    system = np.zeros((size, size))
    system[: problem.n, : problem.n] = mass
    system[: problem.n, problem.n :] = constraint.T
    system[problem.n :, : problem.n] = constraint
    rhs = np.concatenate([force, gamma])
    try:
        solution = np.linalg.solve(system, rhs)
    except np.linalg.LinAlgError:
        solution, *_ = np.linalg.lstsq(system, rhs, rcond=None)
    multipliers = solution[problem.n :]
    reactions = {problem.rows[index].name: float(value) for index, value in zip(rows, multipliers)}
    return Accelerations(qddot=solution[: problem.n], reactions=reactions, force=force)
source: `open_textbook.otkd.problem.dynamics.acceleration_terms` — `solvers/otkd/src/open_textbook/otkd/problem/dynamics.py:245`
def acceleration_terms(problem: Problem, q: np.ndarray, qdot: np.ndarray, g: np.ndarray, theta: np.ndarray):
    """`Φ_q` and `γ`, the two pieces of the acceleration-level constraint."""
    rows = [i for i, row in enumerate(problem.rows) if row.group != SPRING]
    jac = problem.jacobian(q, g, theta)[rows]
    speed = float(np.linalg.norm(qdot))
    if speed == 0.0:
        return jac, np.zeros(len(rows))
    step = 1e-6 / speed
    plus = problem.jacobian(q + step * qdot, g, theta)[rows]
    minus = problem.jacobian(q - step * qdot, g, theta)[rows]
    gamma = -((plus - minus) / (2.0 * step)) @ qdot
    return jac, gamma

Predict first. Integrate the index-1 system with plain RK4 for 0.2 s and never touch the constraint again. Then halve the step. The largest constraint residual at 0.2 s

Choose a prediction

Check answer (without scripting)

Answer: is well above round-off, and falls about sixteenfold when the step halves. The residual is RK4's own global error showing through the constraint: order 4, so halving hh divides it by about 242^4.

Reveal result (lock in your prediction above first)
0.020.0650.110.1550.210⁻¹⁶10⁻¹³10⁻¹⁰10⁻⁷RK4, never projectedRK4 + projection (otkd)t (s)largest |Φ|

| h (ms) | largest |Φ| at 0.2 s, unprojected | ratio to the step before | observed order | projected, largest over the run | | --- | --- | --- | --- | --- | | 20 | 1.34e-06 | | | 7.7e-14 | | 10 | 8.61e-08 | 15.5 | 3.96 | 6.1e-16 | | 5 | 5.46e-09 | 15.8 | 3.98 | 7.8e-16 |

Drift. The reduced system says Φ¨=0\ddot\Phi = 0. Integrate that twice and Φ(t)=Φ(0)+t Φ˙(0)\Phi(t) = \Phi(0) + t\,\dot\Phi(0): any error the integrator leaves in Φ\Phi or Φ˙\dot\Phi is a legitimate solution of the reduced equations, so it stays and accumulates. The residual grows through the run and falls by about 242^4 per halving: RK4's global error, seen through the constraint. At 20 ms it passes 10−610^{-6} in 0.2 s (metres in a length row, a fraction in a quaternion norm), and nothing in the reduced system stops it growing. The projected run sits at round-off at every step (points at 10−1710^{-17} are exact zeros, clipped for the log axis). The cure is §3.

When index reduction and the saddle-point solve breaks
  • Assumes: Φq\Phi_q has full row rank and MM is positive on its null space, so the saddle matrix is nonsingular
  • When it fails: a redundant row makes it singular and the multipliers non-unique (otkd's check faults any redundancy in a dynamics study); near a toggle it is ill-conditioned; and even when it solves, it enforces only Φ¨=0\ddot\Phi = 0, so Φ\Phi drifts
  • Check: the saddle matrix's inertia (nn positive, mm negative eigenvalues) and the constraint residual along the run

3. RK4, projection, and the energy test

Setting: the problem, its sets and its symbols

Problem. Given y˙=F(y)\dot y = F(y) with y=(q,q˙)∈R2ny = (q, \dot q) \in \mathbb R^{2n}, y(0)=(q0,0)y(0) = (q_0, 0), a step hh and a window [0,T][0, T], find the RK4 iterates yj≈y(jh)y_j \approx y(jh), each projected by PP onto M\mathcal M, and the energy drift D(h,T)=max⁡jh≤T∣E(yj)−E(y0)∣D(h, T) = \max_{jh \le T} \lvert E(y_j) - E(y_0) \rvert with its observed order p=log⁡2(D(h,T)/D(h/2,T))p = \log_2\big(D(h, T)/D(h/2, T)\big).

Symbol In Meaning
yy R2n\mathbb R^{2n} the state: poses (m; quaternions dimensionless) and velocities
FF R2n→R2n\mathbb R^{2n} \to \mathbb R^{2n} (q,q˙)↦(q˙,q¨)(q, \dot q) \mapsto (\dot q, \ddot q), with q¨\ddot q from §2's saddle-point solve
q0q_0 Rn\mathbb R^{n} the design pose, released at rest
hh {0.02,0.01,0.005}\{0.02, 0.01, 0.005\} the step (s)
jj {0,1,…,T/h}\{0, 1, \dots, T/h\} the step index
k1,…,k4k_1, \dots, k_4 R2n\mathbb R^{2n} the RK4 stages
TT {0.04,0.06,…,0.2}\{0.04, 0.06, \dots, 0.2\} the end of the window (s)
M\mathcal M ⊂R2n\subset \mathbb R^{2n} {(q,q˙):Φ(q)=0, Φqq˙=0}\{(q, \dot q) : \Phi(q) = 0,\ \Phi_q\dot q = 0\}, the states the linkage allows
PP R2n→M\mathbb R^{2n} \to \mathcal M otkd's projection: Gauss–Newton on Φ\Phi, then a linear correction of q˙\dot q
E=Ek+EpE = E_k + E_p R2n→R\mathbb R^{2n} \to \mathbb R total energy (J): kinetic plus coil and gravity potential
gcoil(q), cg_{\text{coil}}(q),\ c R, R>0\mathbb R,\ \mathbb R_{>0} the coil row's extension (m) and its compliance (m/N)
g, xcom,b(q)\mathbf g,\ x_{\text{com},b}(q) R3\mathbb R^{3} gravity (m/s²) and body bb's centre of mass (m)
D(h,T)D(h, T) R≥0\mathbb R_{\ge 0} the largest energy error over the window (J)
pp R\mathbb R the observed order of the energy error
R(z)R(z) C→C\mathbb C \to \mathbb C RK4's amplification factor on u˙=μu\dot u = \mu u, with z=hμz = h\mu
How these symbols connect

Packing (q,q˙)(q, \dot q) into y∈R2ny \in \mathbb R^{2n} turns §2's saddle-point solve into the first-order vector field F:R2n→R2nF : \mathbb R^{2n} \to \mathbb R^{2n}, which RK4 advances from (q0,0)(q_0, 0) in steps of hh using four stage vectors k1,…,k4k_1, \dots, k_4. After each step, the projection PP maps the iterate back onto the constraint manifold M\mathcal M so both positions and velocities satisfy the linkage constraints. Evaluating the total energy E=Ek+EpE = E_k + E_p (in J, from kinetic energy, the coil's gcoilg_{\text{coil}} and cc, and gravity g\mathbf g at xcom,bx_{\text{com},b}) across [0,T][0, T] gives the peak drift D(h,T)D(h, T), whose halving ratio defines the observed order pp.

Symbol-by-symbol notes
$\mathcal M$ and $P$ — constraint manifold and two-stage projection

The manifold M\mathcal M enforces both Φ(q)=0\Phi(q) = 0 (position level) and Φq(q)q˙=0\Phi_q(q)\dot q = 0 (velocity level). The projection PP restores them in order: first minimum-norm Gauss–Newton steps return qq to Φ(q)=0\Phi(q) = 0, and then one linear minimum-norm update projects q˙\dot q onto ker⁡(Φq(q))\ker(\Phi_q(q)) at the corrected pose.

$E = E\lt em>k + E\lt /em>p$, $g_{\text{coil}}$ and $\mathbf g$ — energy terms and datum

Potential energy sums the coil's elastic term 12gcoil(q)2/c\tfrac12 g_{\text{coil}}(q)^2 / c and the gravitational term −∑bmb g⋅xcom,b(q)-\sum_b m_b\,\mathbf g \cdot x_{\text{com},b}(q), with g\mathbf g pointing downwards in world coordinates. Because gravity uses the geometry file's origin as its height datum, E(y0)E(y_0) depends on that origin, whereas differences E(yj)−E(y0)E(y_j) - E(y_0) do not.

$D(h, T)$ and $p$ — window drift and observed order

For a chosen end time TT, D(h,T)D(h, T) is the largest absolute energy discrepancy over all steps jj with jh≤Tjh \le T. Comparing D(h,T)D(h, T) against D(h/2,T)D(h/2, T) gives the empirical order p=log⁡2(D(h,T)/D(h/2,T))p = \log_2\big(D(h, T)/D(h/2, T)\big); very short windows TT include only a few steps and can sit in a pre-asymptotic regime.

$R(z)$ — linear test-equation amplification factor

On the scalar linear test equation u˙=μu\dot u = \mu u with dimensionless step z=hμ∈Cz = h\mu \in \mathbb C, one RK4 step multiplies uu by the degree-4 polynomial R(z)=1+z+z2/2+z3/6+z4/24R(z) = 1 + z + z^2/2 + z^3/6 + z^4/24. On an undamped linear oscillator zz is purely imaginary, so ∣R(z)∣\lvert R(z) \rvert measures single-step amplitude change while arg⁡R(z)\arg R(z) measures phase error.

$k\lt em>1, \dots, k\lt /em>4$ — stage derivatives, not states

Each stage kr∈R2nk_r \in \mathbb R^{2n} holds a time derivative (q˙,q¨)(\dot q, \ddot q) evaluated at an intermediate state, so hkrh k_r matches the mixed units of yy. Computing the four stages calls §2's saddle-point solve four times per step.

The step. Write the state as y=(q,q˙)y = (q, \dot q) and the index-1 system as y˙=F(y)\dot y = F(y), where FF returns (q˙,q¨)(\dot q, \ddot q) with q¨\ddot q from §2's solve. Classical RK4 takes four stages,

k1=F(yj),k2=F(yj+h2k1),k3=F(yj+h2k2),k4=F(yj+hk3),k_1 = F(y_j),\quad k_2 = F\big(y_j + \tfrac h2 k_1\big),\quad k_3 = F\big(y_j + \tfrac h2 k_2\big),\quad k_4 = F(y_j + h k_3), yj+1=yj+h6 (k1+2k2+2k3+k4),y_{j+1} = y_j + \tfrac h6\,(k_1 + 2k_2 + 2k_3 + k_4),

four saddle-point solves a step, with a local error O(h5)O(h^5) and a global one O(h4)O(h^4) (M01's order, M06's stepper).

The projection. After each step otkd pulls the state back: a few Gauss–Newton steps (minimum-norm least squares) on Φ(q)=0\Phi(q) = 0 and the quaternion norms, then one linear correction of q˙\dot q onto Φqq˙=0\Phi_q\dot q = 0. A Baumgarte term (adding αΦ˙+βΦ\alpha\dot\Phi + \beta\Phi to the acceleration row) is the softer alternative; it trades constraint drift for tuning constants and energy drift.

The energy test. With no damper and no friction the constraints do no work, so E=Ek+EpE = E_k + E_p is constant along the true motion: kinetic, plus the coil's 12gcoil2/c\tfrac12 g_{\text{coil}}^2/c, minus m g⋅xcomm\,g \cdot x_{\text{com}} for each body. Its drift over a run is a check on the integration that needs no reference solution. A check is only as good as its order: measure it (M01).

Reveal result (lock in your prediction above first)
h (ms) projected drift (J) projected order unprojected drift (J) unprojected order
20 2.98e-03 1.38e-03
10 1.56e-04 4.25 6.22e-05 4.47
5 8.82e-06 4.15 3.09e-06 4.33
10⁻²10⁻⁵10⁻⁴10⁻³RK4 + projection (otkd)RK4, never projectedstep h (s)largest |E(t) − E(0)| (J)

Order 4, with or without the projection. The projection moves the state by about the local error, O(h5)O(h^5) a step, so it costs no order: both columns agree. M08 §6 measured order 5 for the energy on a linear oscillator. There RK4 is R(hA)R(hA) with R(z)=1+z+z2/2+z3/6+z4/24R(z) = 1 + z + z^2/2 + z^3/6 + z^4/24; the energy sees only the amplitude, and ∣R(ihω)∣2=1−(hω)6/72+…|R(\mathrm{i}h\omega)|^2 = 1 - (h\omega)^6/72 + \dots, so h6h^6 per step and h5h^5 over a run. Phase error costs nothing on a linear oscillator, because every phase has the same energy. On the quarter car the coil's motion ratio and the gravity potential vary with the pose, so the step's O(h5)O(h^5) error has a part across the energy surface, and the energy inherits the order of the method. Move TT down: over the first few steps the projected run's orders are erratic and can read well above 5, the pre-asymptotic rows of M01 §3, while the unprojected run stays between 4.3 and 4.6. Over the full 0.2 s, with real motion in the window, both read between 4.1 and 4.5 and fall towards 4 as hh shrinks.

Which energy to divide by. E(0)E(0) = 932.6 J in otkd's report, almost all of it gravitational potential measured from z=0z = 0, a datum set by the geometry file's origin, not by the physics. The book's 3 s run at 5 ms quotes 6.3e-08 of the starting value, that is 5.9e-05 J. Against the energy the motion actually exchanges (the peak kinetic energy, 174 J on the 20 ms run) it is 3.4e-07: still small, and now a number that would not change if the road were moved.

source: `open_textbook.otkd.problem.dynamics.integrate` — `solvers/otkd/src/open_textbook/otkd/problem/dynamics.py:369`
def integrate(
    problem: Problem,
    q: np.ndarray,
    qdot: np.ndarray,
    *,
    duration: float,
    steps: int,
    loads: list[tuple[str, str, np.ndarray]] | None = None,
    gravity: np.ndarray | None = None,
    theta: np.ndarray | None = None,
) -> Trajectory:
    """Classical RK4 with projection after every step.

    Projection is not an ornament: RK4 drifts off `Φ = 0` by `O(h⁴)` per step, which over a few
    hundred steps is a visible violation of a rigid link. Projecting `q` onto `Φ = 0` and `q̇` onto
    `Φ_q q̇ = 0` after each accepted step keeps the constraint error at roundoff and is what makes
    the energy test meaningful — the alternative, a Baumgarte term, trades constraint drift for
    energy drift.
    """
    if steps < 2 or duration <= 0:
        raise SolverError("an integration needs a positive duration and at least two steps")
    g = problem.numbers()
    theta = problem.theta0() if theta is None else theta
    h = duration / (steps - 1)
    q = np.array(q, dtype=float)
    qdot = np.array(qdot, dtype=float)

    def derivative(state_q, state_v):
        # A linear combination of unit quaternions is not a unit quaternion, so the intermediate
        # RK4 stages leave the gauge surface. Renormalising before evaluating the acceleration
        # keeps every stage on it; without this the constraint reaction leaks through the radial
        # direction and the energy drifts by an amount that does not shrink with the step.
        stage = state_q.copy()
        for body in problem.moving:
            start = problem._qstart[body] + 3
            norm = float(np.linalg.norm(stage[start : start + 4]))
            if norm:
                stage[start : start + 4] /= norm
        return state_v, accelerations(problem, stage, state_v, loads=loads, gravity=gravity, theta=theta).qddot

    times = np.linspace(0.0, duration, steps)
    states = np.zeros((steps, problem.n))
    velocities = np.zeros((steps, problem.n))
    energies = np.zeros(steps)
    constraints = np.zeros(steps)
    rows = [i for i, row in enumerate(problem.rows) if row.group != SPRING]

    for index, time in enumerate(times):
        if index > 0:
            k1q, k1v = derivative(q, qdot)
            k2q, k2v = derivative(q + 0.5 * h * k1q, qdot + 0.5 * h * k1v)
            k3q, k3v = derivative(q + 0.5 * h * k2q, qdot + 0.5 * h * k2v)
            k4q, k4v = derivative(q + h * k3q, qdot + h * k3v)
            q = q + (h / 6.0) * (k1q + 2.0 * k2q + 2.0 * k3q + k4q)
            qdot = qdot + (h / 6.0) * (k1v + 2.0 * k2v + 2.0 * k3v + k4v)
            q, qdot = _project(problem, q, qdot, g, theta)
        states[index] = q
        velocities[index] = qdot
        energies[index] = energy(problem, q, qdot, gravity, loads)[2]
        constraints[index] = float(np.max(np.abs(problem.evaluate(q, g, theta)[rows])))
    return Trajectory(t=times, q=states, qdot=velocities, energy=energies, constraint=constraints)
source: `open_textbook.otkd.problem.dynamics._project` — `solvers/otkd/src/open_textbook/otkd/problem/dynamics.py:349`
def _project(problem: Problem, q: np.ndarray, qdot: np.ndarray, g: np.ndarray, theta: np.ndarray):
    """Put the state back on the manifold: `Φ(q) = 0` and `Φ_q q̇ = 0`."""
    rows = [i for i, row in enumerate(problem.rows) if row.group != SPRING]
    for _ in range(4):
        values = problem.evaluate(q, g, theta)[rows]
        if np.max(np.abs(values)) < 1e-13:
            break
        jac = problem.jacobian(q, g, theta)[rows]
        step, *_ = np.linalg.lstsq(jac, -values, rcond=None)
        q = q + step
    for _ in range(2):
        jac = problem.jacobian(q, g, theta)[rows]
        drift = jac @ qdot
        if np.max(np.abs(drift)) < 1e-13:
            break
        step, *_ = np.linalg.lstsq(jac, -drift, rcond=None)
        qdot = qdot + step
    return q, qdot
When RK4 with projection, checked by the energy breaks
  • Assumes: the step resolves the fastest mode and the model is conservative
  • When it fails: above hω=22h\omega = 2\sqrt 2 on an undamped mode the energy grows; with a damper or a driven input the energy is not conserved, so its drift no longer measures the integration
  • Check: halve the step: the drift should fall by about 242^4, and the constraint stay at round-off

4. What the energy test cannot see

Setting: the problem, its sets and its symbols

Problem. Given a body bb with mass mbm_b and inertia tensor IbI_b about its centre of mass in design axes, and the 20 ms run (qj,q˙j)(q_j, \dot q_j), find for each bb the largest gap eb=max⁡j∣12ωTIb ω−12ωTRIbRTω∣e_b = \max_j \lvert \tfrac12\omega^{\mathsf T} I_b\,\omega - \tfrac12\omega^{\mathsf T} R I_b R^{\mathsf T}\omega \rvert; and at the pose of largest travel, with q˙=0\dot q = 0, the change in q¨\ddot q when MM becomes M+ΔMM + \Delta M.

Symbol In Meaning
B, b\mathcal B,\ b {chassis,lca,uca,up}\{\text{chassis}, \text{lca}, \text{uca}, \text{up}\} the moving bodies, and one of them
qb\mathsf q_b S3⊂R4S^3 \subset \mathbb R^{4} body bb's unit quaternion, the identity at design
R(qb)R(\mathsf q_b) SO(3)SO(3) its rotation from the design orientation
W(qb)W(\mathsf q_b) R3×4\mathbb R^{3 \times 4} the map from quaternion rates to world angular velocity
ω\omega R3\mathbb R^{3} world-frame angular velocity (rad/s)
mb, Ibm_b,\ I_b R>0, R3×3\mathbb R_{>0},\ \mathbb R^{3 \times 3} mass (kg) and inertia tensor, symmetric positive definite (kg m²)
Jv, JωJ_v,\ J_\omega R3×7\mathbb R^{3 \times 7} derivatives of the centre of mass (m) and of ω\omega over the body's seven pose numbers
MbM_b R7×7\mathbb R^{7 \times 7} the body's block of the mass matrix (kg, kg m²)
ΔM\Delta M Rn×n\mathbb R^{n \times n} JωT(RIbRT−Ib)JωJ_\omega^{\mathsf T}(R I_b R^{\mathsf T} - I_b)J_\omega per body block, the missing rotation
θb\theta_b [0,180][0, 180] the angle body bb turns from design (degrees)
ebe_b R≥0\mathbb R_{\ge 0} the largest rotational-energy error (J)
How these symbols connect

For each body b∈Bb \in \mathcal B, its unit quaternion qb∈S3\mathsf q_b \in S^3 determines both the rotation R(qb)∈SO(3)R(\mathsf q_b) \in SO(3) from the design orientation and the map W(qb)W(\mathsf q_b) taking quaternion rates to world-frame angular velocity ω∈R3\omega \in \mathbb R^3. Combining mbm_b, IbI_b, JvJ_v and JωJ_\omega builds the 7×77 \times 7 mass-matrix block MbM_b, while rotating IbI_b into world axes via RIbRTR I_b R^{\mathsf T} shifts the full mass matrix by ΔM\Delta M. Across the 20 ms trajectory, comparing unrotated and rotated rotational energies yields the peak discrepancy ebe_b (J) alongside the turn angle θb\theta_b, and re-solving §2's system at rest with M+ΔMM + \Delta M measures the effect on q¨\ddot q.

Symbol-by-symbol notes
$\mathsf q_b$ vs $q$ — one body's quaternion vs the full pose

Sans-serif qb∈S3⊂R4\mathsf q_b \in S^3 \subset \mathbb R^4 is the four-component unit quaternion of a single body bb (with ∥qb∥2=1\lVert \mathsf q_b \rVert_2 = 1), not the full nn-vector of poses q∈Rnq \in \mathbb R^n. Its scalar component gives the total rotation angle θb=2arccos⁡∣(qb)0∣\theta_b = 2\arccos\lvert (\mathsf q_b)_0 \rvert from the design orientation.

$R(\mathsf q\lt em>b)$ and $R I\lt /em>b R^{\mathsf T}$ — rotating an inertia tensor

Because IbI_b is given in body design axes, transforming it into world axes at orientation R∈SO(3)R \in SO(3) uses the congruence RIbRTR I_b R^{\mathsf T}, which preserves symmetry and positive definiteness. At the design orientation R=IR = I, the two tensors coincide.

$W(\mathsf q\lt em>b)$ and $J\lt /em>\omega$ — world-frame angular velocity map

Since ω=W(qb)q˙b\omega = W(\mathsf q_b)\dot{\mathsf q}_b is expressed in world axes (rad/s), it pairs directly with the world-frame inertia tensor RIbRTR I_b R^{\mathsf T} in 12ωTRIbRTω\tfrac12\omega^{\mathsf T} R I_b R^{\mathsf T}\omega. Padding W(qb)W(\mathsf q_b) with a 3×33 \times 3 zero block for the body's position coordinates gives Jω=[ 0∣W(qb) ]∈R3×7J_\omega = [\,0 \mid W(\mathsf q_b)\,] \in \mathbb R^{3 \times 7}.

$M_b$ and $\Delta M$ — body block vs full-system perturbation

Each Mb∈R7×7M_b \in \mathbb R^{7 \times 7} is the diagonal block of M∈Rn×nM \in \mathbb R^{n \times n} for body bb's seven coordinates. The correction ΔM\Delta M is likewise block-diagonal across bodies and alters only the 4×44 \times 4 quaternion sub-block of each moving body.

$e_b$ — rotational-energy discrepancy

Measured in joules over all states (qj,q˙j)(q_j, \dot q_j) of the 20 ms run, ebe_b compares otkd's unrotated rotational energy 12ωTIbω\tfrac12\omega^{\mathsf T} I_b\omega against the world-frame value 12ωTRIbRTω\tfrac12\omega^{\mathsf T} R I_b R^{\mathsf T}\omega at the same pose and angular velocity. Evaluating both formulas on the same trajectory isolates the effect of omitting RR.

otkd builds each body's 7×7 block of the mass matrix as

Mb=m JvTJv+JωT I Jω,Jω=[ 0∣W(q) ],ω=W(q) q˙,M_b = m\,J_v^{\mathsf T}J_v + J_\omega^{\mathsf T}\,I\,J_\omega, \qquad J_\omega = [\,0 \mid W(q)\,],\qquad \omega = W(q)\,\dot q,

with JvJ_v the derivative of the centre of mass over all seven pose numbers and W(q)W(q) the map from quaternion rates to the world-frame angular velocity. The rotational energy in world axes is 12ωTR I RTω\tfrac12\omega^{\mathsf T} R\,I\,R^{\mathsf T}\omega, with R(q)R(q) the body's rotation from its design pose; otkd uses II as given. The two agree when R=IR = I, at the design orientation, and .agents/todo.md item 233 records the gap. The question is whether it matters for the quarter car. Over the 20 ms run the bodies turn from design by at most: chassis 0.0° (it slides on a prismatic joint), lower arm 29.8°, upper arm 44.2°, upright 11.1°.

Predict first. The lower arm turns about 30° from design. With its inertia tensor left unrotated, its rotational kinetic energy over the run is wrong by

Choose a prediction

Check answer (without scripting)

Answer: nothing beyond round-off. The arm turns about its hinge axis, and its ω\omega lies along that axis. Then RTω=ωR^{\mathsf T}\omega = \omega and ωTRIRTω=ωTIω\omega^{\mathsf T}RIR^{\mathsf T}\omega = \omega^{\mathsf T}I\omega exactly.

Reveal result (lock in your prediction above first)

lca: turns up to 29.8°, rotational energy up to 0.468 J, error up to 5.6e-15 J (1.2e-12 per cent).

body largest turn (°) largest rotational energy (J) largest error (J)
chassis 0.0 0 0.0e+00
lca 29.8 0.468 5.6e-15
uca 44.2 0.316 1.3e-14
up 11.1 0.114 4.8e-04

The chassis does not turn at all. The arms turn about hinge axes fixed in the chassis, so their ω\omega stays on the axis their rotation leaves alone, and the unrotated tensor is exact for them: the error is round-off. Only the upright, whose spin axis moves as it cambers and steers, sees the missing rotation: 4.8e-04 J, against a peak kinetic energy of 174 J for the whole car (2.7e-06).

Does it change the motion? At the far end of the swing, with q˙\dot q set to zero so that only MM matters, solve §2's system with otkd's MM and again with the rotated tensor. Chassis acceleration (upwards): 11.789636 against 11.789790 m/s²; contact force 6683.148 against 6683.195 N; largest change in any acceleration 1.3e-05 of the largest. For this model item 233 is a relative effect near 10−510^{-5}, below the precision of what §1.6 quotes (a period to the millisecond, camber to 0.001° out of 9.5°). It would not be for a body that tumbles, or a chassis free to roll.

source: `open_textbook.otkd.problem.dynamics.mass_matrix` — `solvers/otkd/src/open_textbook/otkd/problem/dynamics.py:100`

otkd's mass matrix: _inertia(numbers.inertia) enters unrotated.

def mass_matrix(problem: Problem, q: np.ndarray, g: np.ndarray) -> np.ndarray:
    """The 7×7 mass block per moving body, assembled into the full matrix."""
    model: Model = problem.model
    dynamics = model.geometry.dynamics
    if dynamics is None:
        raise SolverError("this model has no `dynamics:` block, so it has no mass")
    matrix = np.zeros((problem.n, problem.n))
    for body in problem.moving:
        numbers = dynamics.bodies.get(body)
        if numbers is None:
            raise SolverError(f"body {body!r} has no mass, so the model has no dynamics")
        block = _body_indices(problem, body)
        offset = _centre_of_mass(problem, numbers)
        matrix[block, block] = _body_block(offset, _inertia(numbers.inertia), float(numbers.mass), q[block])
    return matrix
When the energy test as evidence breaks
  • Assumes: the mass matrix, forces and energy are the physics you meant
  • When it fails: a consistent error in the model (the unrotated tensor) is conserved as faithfully as the truth, so the test passes
  • Check: compute one quantity independently of the code under test, here 12ωTRIRTω\tfrac12\omega^{\mathsf T}RIR^{\mathsf T}\omega against the code's kinetic energy

5. What a damper would add

Setting: the problem, its sets and its symbols

Problem. Given masses ms,mu>0m_s, m_u > 0, rates ks,kt>0k_s, k_t > 0, a damper rate c≥0c \ge 0 and a road step r(t)=r0r(t) = r_0 for t>0t > 0, find x:[0,4] s→R2x : [0, 4]\ \text{s} \to \mathbb R^2 with Mx¨+Cx˙+Kx=(0,ktr)TM\ddot x + C\dot x + Kx = (0, k_t r)^{\mathsf T} and x(0)=x˙(0)=0x(0) = \dot x(0) = 0; then the eigenvalues of AA, the overshoot σ\sigma and the settling time tst_s.

Symbol In Meaning
ms, mum_s,\ m_u R>0\mathbb R_{>0} body and wheel masses (kg), from otkd
TT R>0\mathbb R_{>0} otkd's swing period from §1 (s)
ksk_s R>0\mathbb R_{>0} wheel rate, ms(2π/T)2m_s(2\pi/T)^2 (N/m)
ktk_t [100,400] kN/m[100, 400]\ \text{kN/m} tyre rate, the sketch's own (N/m)
cc R≥0\mathbb R_{\ge 0} damper rate (N s/m)
ζ\zeta [0,2][0, 2] c/(2ksms)c/(2\sqrt{k_s m_s}), the body's damping ratio on a rigid tyre (dimensionless)
x=(xs,xu)x = (x_s, x_u) R2\mathbb R^{2} body and wheel heights from rest (m)
r(t), r0r(t),\ r_0 R\mathbb R road height (m); the step is 10 mm
M, C, KM,\ C,\ K R2×2\mathbb R^{2 \times 2} mass (kg), damping (N s/m) and stiffness (N/m) matrices
y, A, by,\ A,\ b R4, R4×4, R4\mathbb R^{4},\ \mathbb R^{4 \times 4},\ \mathbb R^{4} first-order form y˙=Ay+b\dot y = Ay + b with y=(x,x˙)y = (x, \dot x)
λi\lambda_i C\mathbb C eigenvalues of AA (1/s)
ωi, ζi\omega_i,\ \zeta_i R>0, R≥0\mathbb R_{>0},\ \mathbb R_{\ge 0} a mode's natural frequency ∣λi∣\lvert\lambda_i\rvert (rad/s) and damping ratio −Re⁡λi/∣λi∣-\operatorname{Re}\lambda_i/\lvert\lambda_i\rvert
σ\sigma R\mathbb R overshoot, max⁡txs(t)/r0−1\max_t x_s(t)/r_0 - 1
tst_s R≥0\mathbb R_{\ge 0} the time after which xsx_s stays within 2% of r0r_0 (s)
How these symbols connect

The sprung and unsprung masses ms,mum_s, m_u and §1's swing period TT fix the mass matrix MM and wheel rate ksk_s, while the sliders set the tyre rate ktk_t and reference damping ratio ζ\zeta (hence cc) to form CC and KK. Rewriting Mx¨+Cx˙+Kx=(0,ktr)TM\ddot x + C\dot x + Kx = (0, k_t r)^{\mathsf T} in first-order form y˙=Ay+b\dot y = Ay + b yields the eigenvalues λi\lambda_i of AA, giving each coupled mode's frequency ωi\omega_i and damping ratio ζi\zeta_i. Advancing the response to the road step r(t)=r0r(t) = r_0 over [0,4][0, 4] s produces xs(t)x_s(t), summarised by its dimensionless overshoot σ\sigma and 2% settling time tst_s.

Symbol-by-symbol notes
$\zeta$ vs $\zeta_i$ — slider parameter vs modal damping ratio

The slider value ζ=c/(2ksms)\zeta = c/(2\sqrt{k_s m_s}) is a dimensionless parameterisation of cc taken from the single-mass rigid-tyre oscillator. Once the wheel mass mum_u and tyre rate ktk_t are present, each coupled mode of the 4×44 \times 4 matrix AA has its own damping ratio ζi=−Re⁡λi/∣λi∣\zeta_i = -\operatorname{Re}\lambda_i / \lvert\lambda_i\rvert, which need not match ζ\zeta.

$c$, $C$ and $K$ — symbols reused from §1–§2

In this linear sketch c≥0c \ge 0 is a viscous damper rate in N s/m (not §1's coil compliance in m/N), C∈R2×2C \in \mathbb R^{2 \times 2} is the constant damping matrix (not §1's velocity-product vector), and K∈R2×2K \in \mathbb R^{2 \times 2} is the stiffness matrix (not §2's saddle-point matrix).

$y$, $A$ and $b$ — first-order state-space form

Stacking heights and velocities as y=(xs,xu,x˙s,x˙u)T∈R4y = (x_s, x_u, \dot x_s, \dot x_u)^{\mathsf T} \in \mathbb R^4 gives A=[0I−M−1K−M−1C]A = \begin{bmatrix} 0 & I \\ -M^{-1}K & -M^{-1}C \end{bmatrix} and b=(0,0,0,ktr0/mu)Tb = (0, 0, 0, k_t r_0 / m_u)^{\mathsf T}. Because AA is constant, the step response advances exactly by the matrix exponential eAh\mathrm{e}^{Ah}.

$\lambda\lt em>i$ and $\omega\lt /em>i$ — complex pairs vs real eigenvalues

Eigenvalues of the real matrix AA come either in complex conjugate pairs −ζiωi±i ωi1−ζi2-\zeta_i\omega_i \pm \mathrm{i}\,\omega_i\sqrt{1 - \zeta_i^2} (oscillatory, 0≤ζi<10 \le \zeta_i \lt 1) or as negative real numbers (ζi=1\zeta_i = 1 in −Re⁡λi/∣λi∣-\operatorname{Re}\lambda_i / \lvert\lambda_i\rvert). Their units are s−1^{-1} (rad/s for ωi=∣λi∣\omega_i = \lvert\lambda_i\rvert).

$\sigma$ and $t_s$ — step-response summaries

Overshoot σ=max⁡txs(t)/r0−1\sigma = \max_t x_s(t)/r_0 - 1 is dimensionless (displayed as a percentage) and measures how far the body rises past the step r0r_0, with σ=0\sigma = 0 if xsx_s never exceeds r0r_0. The settling time tst_s is the earliest time after which ∣xs(t)−r0∣≤0.02 r0\lvert x_s(t) - r_0 \rvert \le 0.02\,r_0 holds to the end of the 4 s run.

otkd's quarter car has a rigid tyre and no damper, so it swings for ever. To see what a damper does, use M05's linear two-mass chain and add one. Body msm_s = 300 kg and wheel mum_u = 17 kg are otkd's (the arms and upright lumped at the wheel). The wheel rate ksk_s = 30.3 kN/m is chosen so that, on a rigid tyre, the body's period is otkd's 0.625 s: ks=ms(2π/T)2k_s = m_s(2\pi/T)^2. The tyre rate ktk_t and the damper are the sketch's own; otkd has neither. With x=(xs,xu)x = (x_s, x_u) and a road height rr,

Mx¨+Cx˙+Kx=[0ktr],C=c[1−1−11],K=[ks−ks−ksks+kt].M\ddot x + C\dot x + Kx = \begin{bmatrix} 0 \\ k_t r \end{bmatrix},\qquad C = c\begin{bmatrix} 1 & -1 \\ -1 & 1 \end{bmatrix},\quad K = \begin{bmatrix} k_s & -k_s \\ -k_s & k_s + k_t \end{bmatrix} .

The damper's force depends on the rate of compression, c(x˙s−x˙u)c(\dot x_s - \dot x_u). Write it as y=(x,x˙)y = (x, \dot x), y˙=Ay+b\dot y = Ay + b; the eigenvalues of AA are the modes. With c=0c = 0 they are ±iω\pm\mathrm{i}\omega from Kv=ω2MvK v = \omega^2 M v (M05). With damping each pair becomes λ=−ζiωi±i ωi1−ζi2\lambda = -\zeta_i\omega_i \pm \mathrm{i}\,\omega_i\sqrt{1 - \zeta_i^2}, so a mode's own damping ratio is ζi=−Re⁡λ/∣λ∣\zeta_i = -\operatorname{Re}\lambda/|\lambda|. The slider sets ζ=c/(2ksms)\zeta = c/(2\sqrt{k_s m_s}), the ratio the body alone would have on a rigid tyre. The input is a 10 mm step in the road at t=0t = 0.

Figure 1

Predict first. Raise ζ from 0.3 through 1 (critical for the body on a rigid tyre) to 2. The body's overshoot of the 10 mm road step

Choose a prediction

Check answer (without scripting)

Answer: falls to a minimum near ζ = 1, then rises again. A stiff damper locks body to wheel, and the pair bounces on the tyre spring, which nothing damps. The coupled mode's own damping ratio falls as cc grows.

Reveal result (lock in your prediction above first)
01234-0.9213.387.681216.3bodywheelt (s)height (mm)

Undamped modes (200 kN/m tyre): bounce 1.49 Hz, hop 18.5 Hz. At ζ = 0.30: overshoot 53.5%, inside 2% of the step after 1.69 s.

eigenvalue frequency (Hz) modal ζ
-2.34 ± 9.25i 1.52 0.245
-53.90 ± 100.74i 18.18 0.472
00.511.5224.544.76585.3106ζovershoot (%)

The smallest overshoot on the sweep is 28.8% at ζ = 0.9, not zero: even at critical damping the body overshoots, because the road reaches it through the damper as well as the spring, and the wheel arrives with its own hop. Past the minimum the damper is stiff enough to tie body and wheel together; set ζ = 2 and the table shows what replaces the two modes: a pair bouncing on the tyre near kt/(ms+mu)\sqrt{k_t/(m_s + m_u)} = 4.0 Hz, whose own damping ratio falls as cc rises, and real (overdamped) eigenvalues. Set ζ = 0: overshoot near 100%, the undamped swing of §1.

Why §1.6 leaves the damper out. Three reasons, each about what the section can check rather than what is realistic.

  1. The energy test needs a conservative model. With a damper, E(t)E(t) falls by design, and the check becomes an energy balance, E(t)+∫0tc g˙2 ds=E(0)E(t) + \int_0^t c\,\dot g^2\,\mathrm d s = E(0), with the dissipation integrated alongside the motion by a quadrature whose error now mixes with the integrator's. The clean number §3 measured is gone.
  2. The damper rate is a design choice the chapter has no data for. Every value of ζ gives a different transient (the sweep above), and §1.2–§1.5 contain nothing that would fix one.
  3. It is a model choice, not a missing feature. otkd's forces already carries −(gi/ci+di g˙i)∇gi-(g_i/c_i + d_i\,\dot g_i)\nabla g_i for every spring row, with did_i from a joint's damping; no example declares one. A damped quarter car is the same topology with one more number, and a different test.
source: `open_textbook.otkd.problem.dynamics.forces` — `solvers/otkd/src/open_textbook/otkd/problem/dynamics.py:193`

Gravity, loads, and each spring row's tension plus its damping.

def forces(
    problem: Problem,
    q: np.ndarray,
    qdot: np.ndarray,
    g: np.ndarray,
    theta: np.ndarray,
    loads: list[tuple[str, str, np.ndarray]] | None = None,
    gravity: np.ndarray | None = None,
) -> np.ndarray:
    """Gravity, applied loads, and the springs and dampers' internal forces."""
    model = problem.model
    dynamics = model.geometry.dynamics
    if dynamics is None:
        raise SolverError("this model has no `dynamics:` block, so it has no forces")
    force = np.zeros(problem.n)

    weight = np.asarray(dynamics.gravity if gravity is None else gravity, dtype=float)
    for body in problem.moving:
        numbers = dynamics.bodies.get(body)
        if numbers is None:
            raise SolverError(f"body {body!r} has no mass, so the model has no dynamics")
        block = _body_indices(problem, body)
        w, x, y, z = q[block][3:7]
        jv = _point_jacobian(_centre_of_mass(problem, numbers), w, x, y, z)
        force[block] += jv.T @ (numbers.mass * weight)

    for body, point, applied in loads or []:
        point_jac, _ = problem.point_derivatives(body, point)
        force += np.asarray(point_jac(*q, *g), dtype=float).reshape(3, problem.n).T @ np.asarray(applied)
        point_jac = None

    values = problem.evaluate(q, g, theta)
    jac = problem.jacobian(q, g, theta)
    for index, row in enumerate(problem.rows):
        if row.group != SPRING:
            continue
        joint, component = row.name.split(".", 1)
        compliance = problem.compliance(g).get((joint, component), 0.0)
        gradient = jac[index]
        tension = values[index] / compliance if compliance else 0.0
        damping = _damping(model, joint, component)
        force -= (tension + damping * float(gradient @ qdot)) * gradient
    return force
When one damping ratio per mode breaks
  • Assumes: the modes are well separated, so each keeps its own frequency and damping
  • When it fails: a heavy damper couples body and wheel; the modes merge into a body-on-tyre mode whose damping falls as the damper stiffens
  • Check: the eigenvalues of the first-order system, with modal damping −Re⁡λ/∣λ∣-\operatorname{Re}\lambda/|\lambda| per mode

Practice

Practice A (steps partly filled). The projected quarter car drifts by 2.975e-03 J over 0.2 s at hh = 20 ms and 1.564e-04 J at 10 ms. Ratio =E20/E10=  ?= E_{20}/E_{10} = \;?, then p=log⁡2(ratio)p = \log_2(\text{ratio}). Enter pp.

Worked solution

Ratio =19.0= 19.0, so p=log⁡219.0=4.25p = \log_2 19.0 = 4.25: order 4, settling from above as the step shrinks (§3's table).

Practice B (with a hint). A 300 kg body sits on a 30 kN/m wheel rate on a rigid tyre. What damper rate cc (N s/m) gives it a damping ratio of 0.3?

Worked solution

c=2ζkm=2×0.3×3000=1800c = 2\zeta\sqrt{km} = 2 \times 0.3 \times 3000 = 1800 N s/m.

Hint 1

The damping ratio of one mass on a spring and damper is ζ=c/(2km)\zeta = c / (2\sqrt{k m}).

Hint 2

30000×300=3000\sqrt{30000 \times 300} = 3000, so c=2×0.3×3000c = 2 \times 0.3 \times 3000.

Practice C (on your own). At the far end of the swing the road pushes on the tyre with 6684 N. The car weighs 3110 N (g = 9.81 m/s²). What is the mass-weighted mean vertical acceleration of the car's bodies, in m/s²?

Worked solution

Only gravity and the road act vertically, so ∑mbab,z=N−W\sum m_b a_{b,z} = N - W and aˉ=(N−W)/(W/g)=(6684−3110)/317.0=11.27\bar a = (N - W)/(W/g) = (6684 - 3110) / 317.0 = 11.27 m/s², upwards: the car is being stopped at the bottom of its fall. §2 used the same balance to check λ\lambda.

Mixed practice: which method, and why?

1. You want the quarter car's ride height at rest under its own weight. Which method, and why?

Question 1

2. You want the camber during the first 0.5 s after the wheel hits a kerb. Which method, and why?

Question 2

3. You want the spread of the body's overshoot when the damper rate varies by 15% across production. Which method, and why?

Question 3

Show answers and explanations

1. Solve the static equilibrium directly. At rest the accelerations vanish, so the state solves f−ΦqTλ=0f - \Phi_q^{\mathsf T}\lambda = 0 with Φ=0\Phi = 0: Newton on the KKT system (M02, M04), no time at all.

2. Time stepping the index-1 system with projection. A transient from a given start is an initial-value problem: RK4 on the saddle-point accelerations, projected each step (M06, §3), checked by its energy.

3. Monte Carlo over the damper rate. The overshoot is a nonlinear function of cc (§5's sweep has a minimum), so sample the input distribution and average (M07).

Check yourself (closed book)

1. The quarter car is Mq¨=f−ΦqTλM\ddot q = f - \Phi_q^{\mathsf T}\lambda with Φ(q)=0\Phi(q) = 0. Why can an ODE solver not take it as it stands?

Question 1
How sure?

2. Integrated with RK4 after index reduction and never projected, the quarter car's constraint residual grows over the run. Why does it grow at all?

Question 2
How sure?

3. Halving the RK4 step divides the quarter car's energy drift by about 16, but on M08's linear two-mass sketch it divides it by about 32. Why the difference?

Question 3
How sure?

4. otkd projects onto Φ(q)=0\Phi(q) = 0 and Φqq˙=0\Phi_q\dot q = 0 after every RK4 step. What does that buy?

Question 4
How sure?

5. otkd applies each body's inertia tensor without rotating it. Why does the quarter car still pass its energy test?

Question 5
How sure?

6. The lower arm turns about 30 degrees on its hinge, yet the unrotated tensor gives its rotational energy exactly. Why?

Question 6
How sure?

7. Raise the damper of a two-mass quarter car well past critical. The body's overshoot of a road step

Question 7
How sure?

8. A run reports its energy drift as a fraction of the starting energy. Why is that fraction hard to compare between models?

Question 8
How sure?

Show answers and explanations

1. No equation fixes the multiplier until the constraint is differentiated twice. Φ(q)=0\Phi(q) = 0 contains no λ\lambda and no q¨\ddot q. Differentiate it twice to Φqq¨=γ\Phi_q\ddot q = \gamma and, with the dynamics, the saddle-point system fixes q¨\ddot q and λ\lambda together: index 3 reduced to index 1.

2. Only the constraint's second derivative is enforced, so its errors stay. Φqq¨=γ\Phi_q\ddot q = \gamma says Φ¨=0\ddot\Phi = 0. Any error the integrator leaves in Φ\Phi or Φ˙\dot\Phi satisfies that too, so it stays and accumulates: drift.

3. Nonlinearity turns phase error into energy error. On a linear oscillator RK4's energy error is amplitude loss only, (hω)6/72(h\omega)^6/72 a step, so order 5. A nonlinear linkage turns phase error into energy error, and the energy carries the method's own order.

4. The constraint held to round-off, without lowering the method's order. The correction is the size of the local error, so the order stays 4, and the linkage stays a linkage: a residual near 10−1510^{-15} against 10−610^{-6} unprojected.

5. The integrator conserves the energy of the model it is given, right or wrong. The mass matrix, the velocity term and the energy all use the same unrotated tensor, so the run is a correct integration of a slightly wrong model. Energy verifies the integration, not the model.

6. Its angular velocity lies along the axis the rotation leaves fixed. With Rω=ωR\omega = \omega, ωTRIRTω=ωTIω\omega^{\mathsf T} R I R^{\mathsf T}\omega = \omega^{\mathsf T} I \omega. A body turning about one fixed axis never sees the missing rotation.

7. rises again, because body and wheel lock together and bounce on the tyre. The body-on-tyre mode near kt/(ms+mu)\sqrt{k_t/(m_s + m_u)} appears and its modal damping falls as the damper stiffens. The overshoot has a minimum, near critical.

8. The starting energy includes gravity measured from an arbitrary height. Move z=0z = 0 and the starting energy changes, the drift does not. Divide by an energy the motion exchanges, such as the peak kinetic energy, instead.

Keep these:

  1. A linkage with mass is Mq¨=f−ΦqTλM\ddot q = f - \Phi_q^{\mathsf T}\lambda, Φ=0\Phi = 0: a DAE of index 3, and each multiplier is a force you can check with Newton's law.
  2. Differentiate the constraint twice and solve one saddle-point system per stage; the reduced system holds only Φ¨=0\ddot\Phi = 0, so it drifts at the method's order.
  3. Project after each step: the constraint returns to round-off and RK4 keeps order 4.
  4. On a nonlinear model RK4's energy error is order 4, not the linear sketch's 5; divide it by an energy the motion exchanges, not by a datum-dependent E(0)E(0).
  5. The energy test verifies the integration of the model you wrote, so a consistent error such as an unrotated tensor passes it; for the quarter car that error is tiny.
  6. A damper moves each mode's eigenvalue to the left, but a stiff one locks body to wheel: overshoot has a minimum near critical, and the energy test is lost.

Your connection

Name a simulation you trust because it conserves something. Which error would that conserved quantity be blind to?

Answers

Practice A. p≈4.2p \approx 4.2 from a ratio of about 19: order 4 in the step.

Practice B. c=2ζkm=1800c = 2\zeta\sqrt{km} = 1800 N s/m.

Practice C. (N−W)/(W/g)(N - W)/(W/g), about 11.3 m/s² upwards.

Mixed practice. static equilibrium; time stepping with projection; Monte Carlo.

Where the maths is derived

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

§2 Index reduction and the saddle-point solve

§3 RK4, projection and the energy test

§4 What the energy test cannot see

§5 What a damper would add


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

Back to the book: 1.6 Mass and dampers · Chapter 1 Review

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.