A pendulum above three magnets — where it stops depends chaotically on where it starts. Reveal fractal boundaries with the basin-of-attraction visualiser.
Click anywhere on the canvas to release the pendulum from that point.
A simple steel ball hangs on a rod above a flat surface. Three permanent magnets are placed at the corners of an equilateral triangle beneath it. The ball swings, pulled simultaneously by gravity, the spring restoring force, and three competing magnets. Eventually it settles above one magnet — but which one depends exquisitely on the exact starting position.
This is a canonical physical demonstration of deterministic chaos: the equations of motion are perfectly deterministic, yet the outcome is unpredictable in practice because arbitrarily small differences in initial conditions can change the result.
Nearby starting points can end at different magnets — the hallmark of chaos. Near boundaries the error in predicting the outcome grows exponentially with integration time.
The boundaries between each magnet's basin of attraction are fractals — they are self-similar at all scales and have no smooth sections. No matter how precisely you zoom in, you find more fragmented structure.
The ODE is fully deterministic: given exact initial conditions the future is fixed. Chaos arises not from randomness but from exponential amplification of any uncertainty in those conditions.
The simulation uses 4th-order Runge-Kutta with step dt=0.025 (≈100 steps per real second). This gives excellent accuracy while remaining fast enough for real-time 60 fps animation.
The pendulum bob has position (x, y) measured from the pivot (which projects onto the origin of the magnet plane). The equations governing its motion are:
where k is the linear spring (gravity restoring) constant, d is viscous damping, μ is magnet dipole strength, h is the elevation of the magnets below the pendulum plane (controlling how quickly the magnetic force falls off with distance), and the sum runs over all three magnets at positions (mxᵢ, myᵢ).
The magnetic force law approximates each magnet as a magnetic monopole (valid for small magnets far from the bob): F ∝ μ / r³ where r is the 3D distance from magnet to bob given by √(|pos − magᵢ|² + h²). This (1/r³) law is responsible for the nonlinearity that produces chaos.
Click 🎨 Show Basin to compute the fractal basin diagram. The simulation integrates from rest at each grid point (220×220 pixels, mapping to a ±2.4 world-unit square) and colours each point by the magnet it settles near:
Starting positions from which the pendulum settles above the upper magnet.
Starting positions from which the pendulum settles above the lower-left magnet.
Starting positions from which the pendulum settles above the lower-right magnet.
The boundary between these regions is a fractal set — infinitely intricate at every scale. The fractal dimension of the basin boundary exceeds 1, meaning it is strictly between a curve and a filled area. This is a geometric consequence of chaos: the Wada property — every boundary point borders all three basins simultaneously — has been proved for some parameter ranges of this system.
| Preset | Spring k | Damping d | Strength μ | Elevation h | Behaviour |
|---|---|---|---|---|---|
| 🧲 Standard | 0.5 | 0.10 | 1.5 | 0.30 | Moderate chaos, visible fractal boundary |
| 🌀 Low Damping | 0.5 | 0.03 | 1.5 | 0.30 | Long transients, highly complex trajectories |
| 🛑 High Damping | 0.5 | 0.30 | 1.5 | 0.30 | Quick settling, less chaotic, smoother basins |
| ⚡ Strong Mag | 0.5 | 0.10 | 3.0 | 0.20 | Dominant magnetic force, sharp fractal cusps |
| 🌐 Wide Field | 0.5 | 0.10 | 1.5 | 0.55 | Softer magnetic profile, wider transition zone |
| 💨 Fast Chaos | 0.5 | 0.07 | 2.0 | 0.25 | Fast simulation speed, rich chaotic loops |
| Parameter | Symbol | Role | Chaos effect |
|---|---|---|---|
| Spring constant | k | Linear restoring force toward origin | Higher k → shorter oscillation period, less time chaotic |
| Damping | d | Velocity-proportional energy dissipation | Lower d → longer chaos windows, finer fractal boundary |
| Magnet strength | μ | Magnetic dipole coupling strength | Higher μ → stronger basins, sharper fractal cusps |
| Elevation | h | Magnet depth below pendulum plane | Smaller h → more localised force, stronger nonlinearity |
| Magnet radius | r | Equilateral triangle side scale | Changes balance between spring and magnetic forces |
The Poincaré-Bendixson theorem tells us that 2D autonomous flows cannot be chaotic — they can only have fixed points, limit cycles, or trajectories going to infinity. The magnetic pendulum lives in 4D phase space (x, y, ẋ, ẏ), so this restriction does not apply. The four coupled first-order ODEs allow trajectories to exhibit the defining property of chaos: a positive Lyapunov exponent.
For the Standard preset the largest Lyapunov exponent λ₁ ≈ +0.15 (in dimensionless simulation units), meaning two trajectories initially separated by ε ≈ 10⁻¹⁵ (double-precision floating-point noise) will diverge until they become macroscopically different after only ≈ 15 / 0.15 ≈ 100 time units — about 40 seconds of simulated pendulum motion.
| Area | Connection |
|---|---|
| Lorenz attractor | Both are low-dimensional deterministic ODEs with strange attractors and fractal structure |
| Conservative billiards | Without damping the pendulum is Hamiltonian; KAM theory governs the coexistence of regular and chaotic orbits |
| Julia sets | The basin boundaries share topological properties (Wada lakes) with certain Julia set constructions in complex dynamics |
| Weather prediction | Lorenz's insight: finite-precision measurement + positive Lyapunov exponent = finite predictability horizon |
| Control theory | OGY chaos control: small parameter perturbations can stabilise unstable periodic orbits embedded in chaotic attractors |
Lorenz Attractor · Rössler Attractor · Double Pendulum · Pendulum