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 coefficient0.20
Magnet strength1.0
Pendulum length1.0
Magnet height0.4
Resolution60
Magnet 1 (Red)
Magnet 2 (Green)
Magnet 3 (Blue)
Position X
Position Y
Speed |v|
Final Magnet

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.

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.

Related Engineering Fields

The techniques and concepts used in this magnetic pendulum simulation are directly connected to various advanced engineering fields. First is "handling stability analysis" for automobiles and aircraft. When a car turns a curve at high speed, the relationship between tire lateral force and slip angle is nonlinear. Slight differences in steering angle or road surface conditions can make the vehicle's behavior difficult to predict, which is a form of chaotic behavior. The state-space representation and RK4 method used in the simulator are precisely the same techniques used to solve these vehicle motion differential equations.

Next is "nonlinear vibration analysis" for structures. For example, when skyscrapers or long-span bridges under strong winds experience large deformations, changes in material properties or geometric shape cause the restoring force to become non-proportional to displacement (nonlinear). In such cases, small disturbances at specific wind speeds can potentially trigger large-amplitude, chaotic vibrations. Instead of three magnets, structures have multiple complex modes (vibration patterns) that exchange energy.

Furthermore, "trajectory planning and control for robot arms" is deeply related. The dynamics of multi-joint robot arms are highly nonlinear with complex constraints. There seem to be countless trajectories to a target point (like basins of attraction), and they exhibit sensitivity to initial conditions where a small error in the initial posture leads to a large error in the final posture. The sense of "numerically tracking the behavior of a nonlinear system" developed here is foundational to robot simulation itself.

For Further Learning

If this simulator has piqued your interest, here are some steps to deepen your understanding. Start with the mathematical background. Studying the "logistic map" from an introductory book on chaos theory is recommended. The super-simple recurrence relation $$ x_{n+1} = a x_n (1 - x_n) $$ follows the same path as the magnetic pendulum—stable → period-doubling bifurcation → chaos—just by changing parameter *a*. This will help you grasp the sense that "nonlinearity is the source of chaos."

Next, learn about simulation technology itself. Regarding the "numerical integration methods" at the core of this tool, try coding and comparing the Euler method, improved Euler method (Heun's method), and the RK4 method for a simple problem (e.g., free fall or a spring-mass system). You'll experience why RK4 has higher accuracy and the trade-off with computational cost (number of function evaluations). This forms the foundational knowledge for choosing a "solver" in CAE software.

Finally, it's important to also understand "what is not chaos". Learning about linear systems and bifurcation theory, which precedes chaos, will, in contrast, make the uniqueness of chaos stand out. In engineering, most design is done in the "stable region where chaos does not occur." The process of tweaking parameters in this simulator to find "where chaos begins (the bifurcation point)" is similar to the process of checking safety margins in practical work. As a next topic, the challenge of numerically calculating the "Lyapunov exponent" for this magnetic pendulum to quantify the strength of chaos awaits you.