Chaos and the integrator

Two pendulums released a billionth of a radian apart swing completely differently fifteen seconds later — and the numerical method decides whether energy survives at all.

Runs on
Your browser
Evidence for
Numerical rigour: choosing the method, then checking the invariants
Loading the experiment…This experiment runs in JavaScript, which is turned off. The notes below describe what it shows.

What you’re seeing

Each pendulum in the fan starts a tiny angle to the right of its neighbour — by default a billionth of a radian. For a while they move as one. Then the fan opens: the distance between the first two grows exponentially, a straight line on the log chart, until they share nothing but the pivot.

The slope of that line is the largest Lyapunov exponent, estimated live with Benettin’s method. At λ ≈ 1.3 s⁻¹, every tenfold improvement in how precisely you know the start buys less than two extra seconds of prediction.

Why the integrator matters

Explicit Euler steps along the current slope, which on a curved orbit always overshoots outward: the pendulum gains energy every step. RK4 is fourth-order accurate — at a 2 ms step its energy error stays below 10⁻⁷ through a chaotic half minute — but that error has a direction and keeps accumulating.

The implicit midpoint rule is only second order, yet it is symplectic: it preserves the geometry of Hamiltonian motion, so its energy error oscillates instead of growing. Try the coarse-step preset and compare the lines.

Why this is on a backend engineer’s site

The habit transfers directly: pick the method for the property you cannot afford to lose — energy here, money in a ledger — and then check that property continuously instead of trusting the happy path.

This page’s physics is unit-tested against the analytic normal-mode frequency and against energy conservation, the same way reconciliation jobs verify that settlements and balances still add up.

Point masses on massless rigid rods; damping is optional viscous friction at both joints. The Lyapunov estimate always integrates with RK4 at your step size, so it describes the system rather than the method you picked.

The code behind it

The files that do the work, by their place in this site’s repository.

  • web/src/lab/demos/double-pendulum/
    • engine.tsThe equations of motion, three integrators and the energy that checks them