Pendulum

step 0
Loading the engineShared by all simulations, so the next one opens instantly.
The physics

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 γ=0.5 s⁻¹, released from 90°. The amplitude dies away exponentially, roughly as e−γt/2, and halves about every 2.8 seconds once the swings are small.

Driven (resonance): γ=0.5 s⁻¹ and a drive of amplitude 1.2 rad/s² at 3.13 rad/s, the natural frequency g/L, 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 9.81/1.62≈2.46, so the swing takes about 8.7 seconds.

Governing equation

θ¨=−gLsin⁡θ−γθ˙+Acos⁡(ωdt)

Here θ is the angle from the downward vertical and A is the drive amplitude, an angular acceleration. For small angles sin⁡θ≈θ and the pendulum is a harmonic oscillator with period T0=2πL/g. Without damping and drive, the exact period for an amplitude θ0 is

T=4LgK(sin⁡θ02)=T0(1+θ0216+11θ043072+...),

where K is the complete elliptic integral of the first kind. It grows without bound, logarithmically, as θ0→π. 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 L.

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): A in rad/s², 0 to 5, and ωd, 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, −179° to 179° (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.