Pendulum
This simulation needs WebAssembly, and it could not start in this browser.
The image is a frame from a real run. Check that JavaScript is on, or try another browser.
A weight on a rigid rod, swinging under gravity. Galileo believed that a pendulum takes the same time for a wide swing as for a narrow one, and for small swings that is very nearly true. At large amplitudes it fails: the period grows with the amplitude and diverges as the swing approaches the upside-down position. Christiaan Huygens showed in 1673 that only a bob guided along a cycloid keeps exactly the same period. This simulation integrates the full nonlinear equation, so the effect is there to see.
What you see
The rod hangs from a pivot at the center of the canvas, and the bob leaves a fading trail along its arc. The rod is drawn at the same size whatever its length. The bob starts at rest. At the default timestep and speed, one simulated second takes one second on a 60 Hz display.
Undamped (frictionless): no damping, released from 150°. The swing takes about 3.54 seconds, 76 percent longer than the small-angle period of 2.01 seconds for a 1 m pendulum on Earth. The energy stays constant.
Lightly damped: damping s⁻¹, released from 90°. The amplitude dies away exponentially, roughly as , and halves about every 2.8 seconds once the swings are small.
Driven (resonance): s⁻¹ and a drive of amplitude 1.2 rad/s² at 3.13 rad/s, the natural frequency , starting from 10°. The swings build up and settle into a steady oscillation of about 41° in step with the drive. Linear theory predicts 44°; the real pendulum swings slower at larger amplitude, drifts slightly off resonance and stays a little below that.
Moon gravity (1.62 m/s²): the undamped pendulum from 150° with lunar gravity. Every time in the motion is stretched by , so the swing takes about 8.7 seconds.
Governing equation
Here is the angle from the downward vertical and is the drive amplitude, an angular acceleration. For small angles and the pendulum is a harmonic oscillator with period . Without damping and drive, the exact period for an amplitude is
where is the complete elliptic integral of the first kind. It grows without bound, logarithmically, as . The simulation integrates the equation with fourth-order Runge-Kutta by default, in two substeps per step.
Parameters
Length L (m): 0.1 to 5 m (default 1). The period scales as .
Gravity g (m/s²): 0.1 to 25 (default 9.81).
Damping γ (s⁻¹): the damping rate , 0 to 5 (default 0).
Drive amplitude, Drive frequency (rad/s): in rad/s², 0 to 5, and , 0 to 20 rad/s. Both default to 0, which turns the drive off. A strong drive can make the motion chaotic.
Initial angle (°): the starting angle from the downward vertical, to (default 150°). Close to ±180° the pendulum lingers near the top and the period becomes very long.
timestep dt: 0.0003 to 0.005 s (default 1/600 s).
integrator: Runge-Kutta 4 by default. Leapfrog and Yoshida 4 are symplectic and keep the energy error bounded in the undamped case.