The Spring Pendulum
A point mass suspended from a pivot by an elastic spring. It has two degrees of freedom: it can swing like a pendulum and bounce like a spring. The nonlinear coupling between these modes allows energy to slosh back and forth, producing complex, chaotic trajectories from a remarkably simple setup. Drag the bob to stretch the spring and change the angle, then release it to watch it go.
The system
The generalised coordinates are the radial distance $r$ from the pivot and the angle $\theta$ from the downward vertical. The Lagrangian $L = T - V$ is given by:
Applying the Euler–Lagrange equations $\frac{d}{dt} \frac{\partial L}{\partial \dot{q}} - \frac{\partial L}{\partial q} = 0$ yields the equations of motion for $r$ and $\theta$:
Numerical note
The system is integrated using 4th-order Runge–Kutta (RK4) with a fixed step size. Because of the non-linear coupling (the Coriolis term $-\frac{2 \dot{r} \dot{\theta}}{r}$ and the centrifugal term $r \dot{\theta}^2$), the motion can be highly chaotic. The energy of the system is tracked to monitor integrator stability. If you observe energy drift (visible in the $|\Delta E|$ readout), try reducing the integration speed to take smaller steps per frame.