Deterministic chaos: the double pendulum
Two pendulums start almost identically, a millionth of a radian apart. The equations come from the Lagrangian and are integrated with fourth-order Runge–Kutta. Watch the two trajectories diverge exponentially, and measure the Lyapunov exponent live while total energy stays conserved.
Phase space (θ₂, ω₂)
Separation log₁₀|δ(t)|
Energy error |ΔE/E₀|
From the Lagrangian to the equations of motion
With point masses on massless rigid rods, \(L = T - V\) where
$$ T = \tfrac12 (m_1+m_2) l_1^2\dot\theta_1^2 + \tfrac12 m_2 l_2^2\dot\theta_2^2 + m_2 l_1 l_2 \dot\theta_1\dot\theta_2\cos(\theta_1-\theta_2) $$ $$ V = -(m_1+m_2) g l_1\cos\theta_1 - m_2 g l_2 \cos\theta_2 .$$The Euler–Lagrange equations \(\frac{d}{dt}\frac{\partial L}{\partial\dot\theta_i} = \frac{\partial L}{\partial\theta_i}\) are solved for \(\ddot\theta_1, \ddot\theta_2\) in closed form and integrated with classical RK4 (Δt = 0.5 ms). Optional joint friction enters as the generalised force \(Q_i = -b\,\dot\theta_i\).
Checks you can see
- With b = 0, total energy \(E = T + V\) is conserved. The energy-error plot stays near 10⁻¹⁰ (RK4's local error is \(O(\Delta t^5)\)).
- At small angles the motion is a superposition of two normal modes with \(\omega^2 = \frac{g}{l}(2 \mp \sqrt2)\) (equal masses and lengths). The test suite checks the period to 1 part in 10⁴.
Measuring chaos: the Lyapunov exponent
Nearby trajectories separate as \(|\delta(t)| \approx |\delta_0| e^{\lambda t}\). The slope of the separation plot is \(\lambda/\ln 10\) until δ saturates at the size of the attractor.
The number shown as λ uses Benettin's method. A shadow trajectory is kept at a distance \(d_0 = 10^{-8}\) in phase space and renormalised every τ = 0.05 s:
$$ \lambda = \lim_{t\to\infty}\frac{1}{t}\sum_i \ln\frac{d_i}{d_0} .$$λ > 0 means chaos. For small swings, λ falls toward 0 and the motion is regular.
Things to try
- Start at θ₁ = θ₂ = 10°. The twins stay together and the Poincaré section shows closed curves (invariant tori).
- Start at θ₁ = 120°, θ₂ = −20°. The Poincaré section fills an area: a chaotic sea.
- Make δθ₁ ten times smaller. Divergence is delayed by only \(\ln 10/\lambda\) seconds, which is why long-range prediction fails.
- Add friction: the energy now drops steadily and the motion settles into the stable equilibrium.