A Magnetic Pendulum and Basins of Attraction
Published:
Consider a pendulum with an iron bob which freely swings from a string, rather than a rod with a hinge. It can swing backwards and forwards but also left and right, and anything in between: it has 2 degrees of freedom. We may place magnets on the ground beneath the pendulum which attracts the iron bob. The magnets could have different strengths of attractive forces and could be placed in many configurations. Then, we’d have a very interesting dynamical system when we move the iron bob to a particular initial position and then let the pendulum swing freely. If the magnets are strong enough, the iron bob can be attracted to then eventually hover above one of the magnets but it’s not easy to predict which one based only on the initial position or even first few moments of the trajectory. In this sense, this magnetic pendulum system is similar to a 3 body celestial system with a small satellite orbiting (or possibly crashing) around them. I’m introducing the magnetic pendulum system because you can make a model of it at home with some magnets and string.
It can be great fun to animate the dynamics as has been done many times on YouTube but I figured it could be fun to implement in Python with the help of AI. For simplicity, we’ll assume the magnets are all of equal strength and arranged in an equilateral triangle. Here is a particular initial position where for a short time, the pendulum appears to be attracted to the top magnet but then is attracted to the left magnet. We can also bring in initial velocities but for our purposes, we’ll only consider initial positions.
Here is an animation with several initial positions for the pendulum. The playback speed of the videos can be slowed down to help track a specific point’s trajectory. Note that some of the points start out close to each other but end up attracted to different magnets. Indeed, this is an example of a chaotic system since small deviations in initial conditions can lead to drastically different paths and final results; cf. animation of the chaos of the double pendulum.
Here is a graphic showing the basins of attraction. That is, we color the plane with three colors. A particular point $p$ in the plane is given the color corresponding to the magnet that the pendulum eventually is attracted to if it begins at point $p$. There are points which would not be given a color as the forces perfectly balance out. For example, the exact barycenter of the three magnets is one such point. One can see that there are fractal-like patterns at play.

Here is another image of higher fidelity in Zenzicubic’s video. The colors are different and the configuration is rotated by 30 degrees but one can see some similarities to the image I generated. One thing of note is that in my image with the three largest basins, in each one there are two pockets of other colors. In this higher fidelity image, there’s more detail to those pockets and we actually see a mix of two colors surrounded by the third color of the larger basin.

One can make the system more interesting by having larger/smaller magnets placed in different configurations and also giving the pendulum an initial push. We can also add more magnets and change the length of the string.
