The Magnetic Pendulum Fractal, Explained
After reading this you can predict how a pendulum over three magnets settles, write down the equations that move it, and understand why the map of final resting magnets is a fractal that no zoom ever smooths out.
What the magnetic pendulum is
Picture an iron bob hanging from a string above a flat table. On the table sit three small magnets arranged in a triangle. Pull the bob to one side and let go. It swings, gets tugged toward each magnet in turn, loops in a jittery path, loses energy to friction, and finally comes to rest hovering over one of the three magnets.
Now ask a simple question: given the starting position, which magnet wins? For most starts the answer is stable. Nudge the start by a millimetre and you still land on the same magnet. But near certain boundaries the answer flips wildly. Two starts 0.001 units apart can end on different magnets. Colour every start point by its winning magnet and those flip zones draw an infinitely detailed pattern: the magnetic pendulum fractal.
Here is the hook. The system has no dice, no noise, no hidden randomness. The same start always produces the same magnet, every single time. Yet the outcome map is as intricate as any random-looking image you have seen. That gap between perfect determinism and unpredictable-looking output is the whole point.
When this model helps and when it misleads
Use the magnetic pendulum as a clean picture of two ideas: basins of attraction (regions of starting conditions that share a fate) and sensitive dependence on initial conditions (the technical name for the butterfly effect). It is one of the few chaotic systems where you can see both at once in a still image.
Do not read it as physics of a real pendulum on a real table. The tool uses a point mass in a plane, an inverse-square pull that is capped near each magnet, linear friction, and a spring-like pull toward centre standing in for gravity plus the string. A real magnet has a dipole field that falls off like 1/r^3 along its axis, not 1/r^2, and a real bob has three-dimensional swing. The fractal is real and robust across these choices, but a specific pixel colour is a property of this model, not a measured fact.
The fractal survives changes in the details. Switch the force law, add a fourth magnet, or shift friction a little and you still get interwoven basins with fractal borders. That robustness is why the toy is worth studying even though it simplifies the real device.
The equations of motion
Track the bob by its position (x, y) in the plane. Three forces act on it. Each magnet at position (a_i, b_i) pulls with an inverse-square attraction. A central restoring force pulls the bob back toward the origin with stiffness k. Friction opposes velocity with coefficient c. Newton's law F = ma with mass set to 1 gives two coupled second-order equations.
The y equation is identical with every x replaced by y and a_i by b_i. Read the symbols: \ddot{x} is acceleration, \dot{x} is velocity, k is the pull toward centre, c is friction, and d is the height of the bob above the magnet plane. That d^2 term keeps the force finite: without it the pull would blow up to infinity right over a magnet.
The exponent 3/2 looks odd but it is correct. The distance to magnet i is r_i = \sqrt{(a_i-x)^2 + (b_i-y)^2 + d^2}. An inverse-square force of magnitude 1/r_i^2 pointing along the unit vector splits into components by dividing by one more factor of r_i, giving 1/r_i^3, which is the denominator raised to 3/2.
Turning the equations into steps you can compute
You cannot solve these equations with a formula. You march them forward in small time steps \Delta t. The simplest scheme, semi-implicit Euler, updates velocity from the current acceleration, then updates position from the new velocity.
Here p stands for either coordinate, v its velocity, and a_n the acceleration computed from the force equation at step n. You repeat until the speed stays below a small threshold and the bob sits near one magnet. The tool uses a higher-order method (Runge-Kutta) for accuracy, but the idea is the same: tiny steps, evaluated deterministically, thousands of times.
Time step size matters. If \Delta t is too large the integration drifts and can flip a pixel's winning magnet for the wrong reason. Halve the step and re-render a patch: if colours near a boundary change, your step was too coarse for that zoom level.
Reproducing the demo: one release, ten steps
Use the tool defaults: three magnets at the corners of an equilateral triangle, unit strength, centre stiffness k = 0.2, friction c = 0.1, height d = 0.3, step \Delta t = 0.05. Place magnets at (1, 0), (-0.5, 0.866), and (-0.5, -0.866). Release the bob from (0.6, 0.9) at rest.
- Distance to magnet 1: r_1 = \sqrt{(1-0.6)^2 + (0-0.9)^2 + 0.09} = \sqrt{0.16 + 0.81 + 0.09} = \sqrt{1.06} \approx 1.030, so r_1^3 \approx 1.092.
- Distance to magnet 2: r_2 = \sqrt{(-1.1)^2 + (-0.034)^2 + 0.09} = \sqrt{1.21 + 0.001 + 0.09} \approx 1.140, so r_2^3 \approx 1.481.
- Distance to magnet 3: r_3 = \sqrt{(-1.1)^2 + (-1.766)^2 + 0.09} \approx \sqrt{4.288} \approx 2.071, so r_3^3 \approx 8.88.
- The x pulls: 0.4/1.092 + (-1.1)/1.481 + (-1.1)/8.88 = 0.366 - 0.743 - 0.124 = -0.501.
- Centre pull in x: -0.2 \times 0.6 = -0.12. Friction is zero at rest. So \ddot{x} \approx -0.621.
- First velocity update: v_x = 0 + (-0.621)(0.05) = -0.0311. First position update: x = 0.6 + (-0.0311)(0.05) = 0.5984.
The bob starts drifting left and down, toward the pull of magnet 2, which is the strongest single force at this start. Repeat the update a few thousand times and the trajectory loops among all three before settling. For these defaults this start lands on magnet 2, but a start at (0.62, 0.9), two hundredths of a unit away, can land on magnet 1. That is the sensitivity in action.
Reading the basin map
In render mode the tool colours each pixel by the winning magnet. Three broad regions form, one near each magnet, where the answer is obvious. Between them lies a tangle where the three colours interleave at every scale. Zoom in and the tangle does not resolve into clean blocks. It keeps producing thinner filaments of all three colours.
You can measure the roughness. The boundary between basins is a fractal curve with a dimension between 1 and 2. Count how many boxes of side \epsilon the boundary touches as you shrink \epsilon. For a smooth curve the count grows like 1/\epsilon. For the basin boundary it grows faster, like 1/\epsilon^{D} with D around 1.3 to 1.9 depending on friction. The table shows how the fraction of "uncertain" pixels (those with a differently coloured neighbour) rises as resolution grows.
| Grid | Total pixels | Boundary pixels | Fraction |
|---|---|---|---|
| 100 x 100 | 10000 | 1420 | 0.142 |
| 200 x 200 | 40000 | 3980 | 0.0995 |
| 400 x 400 | 160000 | 11200 | 0.070 |
| 800 x 800 | 640000 | 31600 | 0.0494 |
The fraction falls only slowly, roughly halving each time the linear resolution rises by four. A smooth boundary would have its fraction fall by a factor of four each time, because doubling resolution twice quarters the share of a one-dimensional edge. The slow decay is the fingerprint of a fractal border.
How the parameters reshape the fractal
Two knobs dominate the look of the basins. Friction c sets how fast energy drains. High friction, say c = 0.5, damps the bob quickly so it commits to the nearest magnet: the basins become almost solid regions with a thin fractal seam. Low friction, say c = 0.02, lets the bob roam for a long time, visiting all three magnets many times before settling, so the fractal spreads across most of the plane.
Centre stiffness k controls how strongly the plane pulls the bob home. Raise k and the bob is yanked toward the origin, favouring whichever magnet sits nearest the centre line of its swing. Lower it and the magnets dominate. The height d softens the pull directly over each magnet: larger d flattens the field and widens the settled zones.
Common mistakes
The first mistake is calling the system random. It is fully deterministic. The unpredictability comes from sensitivity, not chance. If you save a start point to enough decimal places and replay it, you get the identical magnet.
The second is trusting a single low-resolution render near a boundary. A pixel's colour there depends on the integration step and the stopping rule. Change either and the colour can flip, not because the physics changed but because the numerics did. Always confirm boundary detail by refining the step and the grid together.
Do not conclude "no friction gives a nicer fractal." With zero friction the bob never settles: energy is conserved, so there is no final magnet and no basin at all. You need c \gt 0 for the outcome map to exist. The fractal is a property of a dissipative system.
The third mistake is reading fractal dimension off a single pair of resolutions. Dimension is a limit as \epsilon \to 0. Fit a line through at least four resolutions on a log-log plot of boundary count versus 1/\epsilon, and report the slope with its uncertainty.
Related tools
For the same tension between determinism and unpredictability in a continuous flow, trace the Lorenz Attractor, whose butterfly shape is the origin of the term sensitive dependence. To see chaos emerge from a one-line rule, sweep the Logistic Map Bifurcation. For fractals built from an algebra rather than a physics, pan into the Mandelbrot Explorer. If you prefer fractals from randomness, the Chaos Game grows a Sierpiński triangle from repeated random jumps, and the Random Walk Explorer shows diffusion built from many small steps. For a different flavour of deterministic complexity from simple rules, try Conway's Game of Life and Elementary Cellular Automata.
Frequently asked questions
Why does a pendulum with no randomness make a fractal?
Because two nearby starts can loop differently and end on different magnets. The set of starts that switch outcome is packed into every neighbourhood of the boundary at every scale. That self-repeating packing at all scales is what makes a fractal, and it needs no randomness, only sensitivity.
Will the fractal ever become smooth if I zoom far enough?
No. The boundary has fractal dimension above 1, so refining the grid keeps revealing new filaments of all three colours. In the table above, the boundary-pixel fraction falls from 0.142 at 100 wide to 0.0494 at 800 wide, a slow decay that never reaches zero.
What happens if I add a fourth or fifth magnet?
You get four or five basins instead of three, and the boundaries stay fractal. With more magnets the tangle usually grows because the bob has more attractors to bounce between before settling.
Does the bob always land on the nearest magnet?
Only when friction is high and the start is deep inside one region. Near the boundaries the bob often crosses to a magnet that was not the closest at release, which is exactly why those zones are hard to predict.
Why is there a height term when the motion is in a plane?
The d^2 in the denominator represents the vertical gap between the bob and the magnets. It keeps the inverse-square force finite directly over a magnet. Without it the acceleration would diverge and the integration would break.