A simple machine with a complicated answer
Hang a small magnetic bob on a pendulum above a flat plate holding three (or more) fixed magnets, arranged symmetrically. Release the bob from rest somewhere above the plate. Gravity pulls it back toward the centre, the magnets pull it sideways, and a little friction bleeds energy out of the system on every swing. Eventually the bob settles, motionless, directly above exactly one magnet. The question the simulation asks is the simplest one imaginable: which magnet?
For release points far from the centre, or nearly straight above one magnet, the answer is obvious and the pendulum swings there directly. Nearer the middle, where the three magnetic pulls are almost balanced, the outcome becomes extraordinarily sensitive: nudging the release point by a fraction of a millimetre can flip the final resting magnet.
The equations, and why they need a real integrator
The bob's horizontal motion obeys Newton's second law with three forces summed together: a restoring spring-like term pulling it back toward the centre (from the pendulum's swing), a damping term proportional to velocity (friction and air drag), and an inverse-square-like attraction toward each magnet:
m·a = -k·x - b·v + Σ_i C · (m_i - x) / |m_i - x|^3
↑ ↑ ↑
restoring damping attraction toward each magnet m_i
This is a smooth, deterministic ODE with no explicit randomness anywhere — yet its solutions are chaotic, in the strict sense of having sensitive dependence on initial conditions. A fixed-step integrator like RK4 is standard here because the trajectories near a magnet curve sharply and an inaccurate step can flip which magnet ultimately wins, exactly the kind of error a chaotic system amplifies rather than averages away.
Painting the basin map
Instead of dropping one bob, colour every point on the plate by which magnet a pendulum released from rest there eventually settles on — magnet 1 red, magnet 2 green, magnet 3 blue. Far from the centre you get large, clean, single-coloured regions: the basins of attraction of each magnet. Close to the boundaries between basins, the three colours interleave at every scale you zoom into, in the manner of a fractal — the boundary has no smallest feature, and no matter how much you magnify a boundary region, you keep finding more interleaved structure rather than three clean bands.
Why the boundary is fractal, not just messy
The fractal structure is a direct fingerprint of chaos. Two release points on opposite sides of a boundary follow trajectories that initially look identical, since they experience nearly the same forces — but the tiny difference between them grows exponentially with time (a positive Lyapunov exponent), until eventually the two trajectories diverge toward different magnets. Because that exponential separation happens at every scale, shrinking the gap between two starting points by a factor of ten only buys a fixed extra number of swings before the two points diverge again — which is precisely the self-similarity that defines a fractal boundary.
Why this matters beyond a desk toy
The magnetic pendulum is a favourite teaching example precisely because it is fully deterministic, easy to build on a desk, and still produces genuinely unpredictable long-term behaviour — a vivid rebuttal to the intuition that "no randomness in the equations" should mean "predictable outcome". The same basin-of-attraction structure with fractal boundaries shows up in far more consequential multistable systems: power grids that can settle into different stable operating states after a fault, ecosystems with multiple stable population equilibria, and Newton's-method root-finding on the complex plane, whose basin boundaries are fractal for exactly the same underlying reason.
Frequently asked questions
Does the pendulum always eventually stop over a magnet?
With any friction in the model, yes — energy is dissipated every swing, so the bob eventually loses enough kinetic energy to be captured by the potential well of whichever magnet it happens to be nearest when it finally runs out of energy to escape. Without friction the motion never settles and can wander over the magnets indefinitely.
Why can I not predict which magnet the pendulum will pick just from the release point?
Because the system is chaotic: it has sensitive dependence on initial conditions, so two release points a fraction of a millimetre apart can be sorted into different basins after enough swings. The boundary between basins is a fractal with no smallest scale, so no amount of measurement precision lets you predict the outcome near it.
Is a fractal basin boundary the same thing as the Mandelbrot set?
No, though both are fractals born from iterating a rule. The Mandelbrot set comes from iterating a fixed complex map and colouring points by whether the orbit escapes. A basin-of-attraction fractal comes from a continuous dynamical system with several stable equilibria; its fractal structure reflects how sensitively the long-term fate depends on the starting condition, not on escape from a map.
Try it live
Everything above runs in your browser — open Magnetic Pendulum and change the parameters while it is running. Nothing is installed, nothing is uploaded, the whole model lives in one tab.
▶ Open Magnetic Pendulum simulation