Magnetic Pendulum Chaos Simulator Back
Chaos & Nonlinear Dynamics

Magnetic Pendulum Chaos Simulator

Color-code each grid point by which magnet the pendulum eventually falls to, revealing a beautiful fractal basin of attraction. Experience how tiny differences in initial conditions lead to completely different outcomes.

Parameters

Damping coefficient
Magnet strength
Pendulum length
Magnet height
Resolution
Magnet 1 (Red)
Magnet 2 (Green)
Magnet 3 (Blue)
Results
Position X
Position Y
Speed |v|
Final Magnet
Main

Click the canvas to launch the pendulum from any initial position. The basin is rendered by computing the final attractor for each grid point via RK4 integration.

What is a Magnetic Pendulum?

🙋
What exactly is this simulator showing? I see a pendulum swinging over three magnets, and the screen is filling with colored dots.
🎓
Basically, it's mapping chaos. The pendulum bob is made of metal, and it's swinging over three repelling magnets. Each colored dot on the grid represents a different starting position for the pendulum. The color shows which magnet the pendulum eventually ends up pointing towards when it stops swinging. Try clicking on the grid to drop the pendulum from that point and watch its chaotic path.
🙋
Wait, really? So if I start it from two points that are super close together, it could end up at totally different magnets? That seems unpredictable.
🎓
Exactly! That's the core of chaos—extreme sensitivity to initial conditions. In practice, the forces from the three magnets compete, making the pendulum's path incredibly complex. This is why the colored regions, called 'basins of attraction,' have such intricate, fractal boundaries. Try moving the 'Damping' slider to zero. You'll see the pendulum never settles, illustrating how energy loss is needed for it to finally choose a magnet.
🙋
So the fractal pattern is the boundary between the colors? Why does it look so detailed no matter how much I zoom in?
🎓
In practice, yes. That infinite detail at the boundary is a key feature of fractals. Near any point where two colors meet, you'll always find a tiny speck of the third color. This happens because at those boundaries, the pendulum's fate is undecided. A common case is in fluid mixing. This simulator's 'Magnet Strength' and 'Pendulum Length' sliders directly change the shape of these fractal basins—stronger magnets make the boundaries more wild and complex.

Physical Model & Key Equations

The motion is governed by Newton's second law, accounting for gravity, magnetic repulsion, and damping. The net force on the pendulum bob is the vector sum of all forces.

$$ m \frac{d^2 \vec{r}}{dt^2}= \vec{F}_g + \vec{F}_{damp}+ \sum_{i=1}^{3}\vec{F}_{magnet, i}$$

Where:
$m$ is the bob's mass,
$\vec{r}$ is its position vector,
$\vec{F}_g$ is gravity ($mg$ downward),
$\vec{F}_{damp}$ is the damping force (proportional to $-b\vec{v}$, controlled by the Damping slider),
$\vec{F}_{magnet, i}$ is the repulsive force from the $i$-th magnet.

The magnetic force is modeled as an inverse-square repulsion from each magnet's fixed position. This is a simplified model that captures the essential chaotic dynamics.

$$ \vec{F}_{magnet, i}= \frac{k}{|\vec{r}- \vec{r}_i|^3}(\vec{r}- \vec{r}_i) $$

Where:
$k$ is the magnetic strength constant (controlled by the Magnet Strength slider),
$\vec{r}_i$ is the fixed position of magnet $i$,
The denominator's cube comes from assuming a magnetic dipole repulsion. This force grows rapidly as the pendulum gets close to a magnet, creating the fierce competition that leads to chaos.

Frequently Asked Questions

The colors indicate the magnet where the pendulum ultimately stops. Each of the three magnets is assigned a different color, visualizing how the initial position determines which magnet attracts the pendulum.
Reducing the damping coefficient makes the pendulum motion last longer, emphasizing chaotic behavior. Increasing the magnetic strength complicates the basin boundaries, making the fractal patterns more distinct. Small differences in initial conditions significantly affect the results.
Lowering the resolution (reducing the number of pixels) decreases the computational load and speeds up the process. Additionally, setting a shorter maximum time step for the simulation or narrowing the rendering range can also lighten the processing.
This is a simplified model that includes approximations of air resistance and magnetic forces, so it lacks quantitative accuracy. However, as an educational demonstration of chaos theory, it helps in understanding sensitivity to initial conditions and fractal structures.

Real-World Applications

Secure Communication & Cryptography: The extreme sensitivity to initial conditions makes chaotic systems ideal for encrypting data. Small changes in the starting parameters (like magnet positions) generate completely different, unpredictable signals that can mask information, making it very hard to intercept and decode.

Fluid Mixing & Chemical Engineering: The intricate fractal boundaries seen in the basins are analogous to how fluids mix. Understanding this chaotic advection helps engineers design more efficient industrial mixers or reactors, ensuring two substances blend thoroughly and quickly.

Weather & Climate Modeling: The atmosphere is a chaotic system. Just like the pendulum's final magnet depends minutely on its start point, long-term weather predictions are inherently limited because we can never measure initial conditions (temperature, pressure, etc.) perfectly at every point on Earth.

Planetary Orbit Stability: The three-body problem in astrophysics (like a small asteroid moving under the gravity of the Sun and Jupiter) exhibits similar chaotic dynamics. Studying basins of attraction helps predict whether an orbit will be stable or ejected from the system over astronomical timescales.

Common Misconceptions and Points to Note

When you start using this simulator, there are a few points you should be careful about. First is the misconception that "since a tiny change in the initial position leads to a drastically different result, the calculations must be ultra-precise". While sensitivity to initial conditions is indeed at the heart of chaos, the numerical errors in the simulation itself can be interpreted as "different initial values." Therefore, the choice of calculation method (RK4 in this tool's case) and time step (Δt) is critically important. For example, if you coarsen Δt from 0.01 seconds to 0.1 seconds, the visual trajectory can change completely, leading you to observe "chaos due to numerical error" rather than the intended "deterministic chaos." In practical engineering, there's a pitfall where making the mesh size or time step too coarse can generate non-physical oscillations.

Next is the balance of parameter settings. Making the damping coefficient γ close to zero allows energy conservation and can produce complex, beautiful trajectories. However, in real physical systems, damping from factors like air resistance always exists. Conversely, setting γ too high causes the pendulum to stop moving quickly, reducing the interesting chaotic behavior. For instance, in a system with mass m=1 and magnetic force k=1000, γ around 0.1 to 0.5 often provides a good balance between adequate damping and complex motion. In real-world CAE, setting a damper's damping coefficient to an unrealistic value is a classic example leading to simulation results that don't match actual test data.

Finally, don't assume "this simulation is perfectly realistic". The model for the magnetic force here is a simplified one that doesn't fully replicate the force between real magnetic dipoles. The parameter ε is also a "tweak" to stabilize the calculations. This approach is common in CAE, where complex phenomena are first approximated with easier-to-understand linear spring models. The first step is not perfect reproduction, but extracting the essence of the phenomenon.

How to Use

  1. Set damping coefficient (0–0.5) using s-damp slider to control energy dissipation; higher values stabilize trajectories faster
  2. Configure magnet count (2–4) with s-magNum and magnet strength (0.5–2.0 Tesla) via s-mag to define basin geometry
  3. Adjust pendulum length (0.1–1.0 m) with s-len and magnet height (0.05–0.5 m) via s-mh to alter attractors' relative positions
  4. Click canvas to release pendulum from selected position; color indicates which magnet basin that initial condition converges to

Worked Example

Set damping=0.2, magnet count=3, magnet strength=1.2 T, pendulum length=0.5 m, magnet height=0.15 m. Release from offset 15° angle. Pendulum oscillates with decreasing amplitude (~15% energy loss per swing). Trajectory enters red basin and converges to lower-right magnet within 8–12 cycles. Adjacent release point (14.9°) may converge to different magnet, revealing fractal sensitivity characteristic of chaos.

Practical Notes

  1. Damping ~0.1–0.15 produces richest fractal patterns; below 0.08 yields perpetual chaotic motion, above 0.3 eliminates basin mixing
  2. Three-magnet configuration (equilateral spacing) generates classic Wada boundaries; four magnets create more complex interwoven basins
  3. Magnet strength >1.5 T compresses basins toward attractors; <0.7 T widens intermingled regions and increases computational sensitivity
  4. Pendulum length inversely affects natural frequency; longer arms (0.8–1.0 m) show slower convergence with broader chaotic regions