The Chaotic Compass

A rusty nail placed near a faithful compass, will sway it from the truth, and wreck the argosy.
- Walter Scott

Abstract

In this assignment I will be using the opensourcephysics library to simulate the motion of a compass in a magnetic field. A Java applet is provided to experiment with allowing the user to perform simulations of compasses in various oscillating magnetic fields.

The Assignment

" Consider a compass needle that is free to rotate in a periodically reversing magnetic field which is perpendicular to the axis of the needle. Choose an appropriate numerical method for solving the equation of motion and plot the Poincaré map at time t=2πn/ω . Verify that if the parameter

λ=Sqrt(2Bmu/Iw^2) >1

then the motion of the needle exhibits chaotic motion. "

The simulation
The physics involved
The source code
The compass class

The Simulation

The applet above uses a Verlet algorithm to solve the differential equation of motion. The results are plotted in output windows of Phase Space and Poincare. The Poincare plot is simply a reading of the position of the system in phase space at times 2πn/ω. A typical run is shown in figure 1 below:

Poincare plotPhasespace plot
Figure 1: Poincare and Phasespace plots for a typical run: ω=4, B=17, μ=1, I=1

Detecting Chaos

Chaotic behaviour is described by the exponential deviation of nearby trajectories. In laymans terms this means that changing a variable a very small amount can cause a big change in the system. In figure 2 below we see a phase space plot in three colour - black, red and blue, for three very close initial points at times at which the phase of the magnetic field was the same. The paths taken through phase space do diverge very quickly and after a small initial stage appear to bear no resemblance to one another:

Chaos in Phase Space
Figure 2: Chaotic motion in phase space, ω=1, B=6, μ=0.5, I=1 λ=2.45

This is easy to compare to a similar system with a different set of parameters, set so that the λ value was < 1. In figure 3 below we see that nearby points in phase space stay fairly close to one another as time progresses for this setup:

Non Chaos in Phase Space
Figure 3: Non-chaotic motion in phase space, ω=1, B=0.99, μ=0.5, I=1 λ=0.995

So we do indeed see that the parameter λ is a predictor of chaos - if λ >1 we have chaos, if not, we do not have chaos.

Extending The Interface

It's all very well for us physicists to look at a phase-space diagram and nod in agreement that indeed we have found a chaotic motion. However since a simulation is not always intended to be viewed by those with the exact same background as ourselves I decided to extend the project somewhat.

Compass Display

The most natural thing to do when simulating a compass is in fact display the compass!

The Compass Display
Figure 4: The compass displayed

The coding behind this was fairly trivial - just finding the X and Y coordinates using simple trigonometry and then plotting points from the origin out to the radius. Since the compass is now displayed it might as well be interactive. Clicking on the compass at any time during the simulation will re-orient the system so that the compass is pointing in the direction specified by the users click and has no velocity. This is all done using the interactive mouse handler - see the code for details. On a side note, there is one unattractive fudge used in the code - determining which frame has been clicked on by calling for it's preferred size. I would have preferred to simply name the objects and treat them separately. However this information was not being passed to the mouse handler I had to find information that the mouse handler did indeed access. The preferred maximum of the X values of the two frames in question is easily

Phase Space Interactivity

The next logical step was to allow the phase-space plot to become interactive. Clicking at any point in phase space will shift the system to that point in phase space. This is particularly useful since we are trying to see how close initial points in phase space diverge over time, and because the control interface for this program involves an unwieldy number of user defined variables. Each time the phase space plot is clicked the color of the line drawn is changed to make it easier to distinguish between altered data sets. If the left button is pressed, the time is reset, so we can easily assess the effect of altering the initial conditions slightly about a point - just click around the initial point in phase space.

Phase space with colours
Figure 5: The Phase Space Diagram with various initial data defined using mouse clicks. ω=3, B=1, μ=1, I=1 λ=0.47

As we can see in Figure 5 above the various initial conditions in phase space, depicted by the different coloured paths, did not lead to a great deviation for a variety of initial conditions. This is the power of having such a simple interface - it allows the user to quickly test a lot of initial conditions without having to go through the control interface each time. Whilst the control interface is far more accurate for doing precise tests, the mouse driven interface saves a lot of time when experimenting.

Extending the Physics

As described in the page on the physics I have extended the equation of motion to include a damping effect. This is based on the idea that the compass is in fact suspended in a liquid and not entirely frictionless. The damping parameter, γ can be set from the program control and will typically be a number less than 1. This can be altered to give an anti-damping effect which although unphysical can lead to some interesting simulations.

Fun Things To Try

There are a number of interesting intial sets of data to try for various results:

Example Name Damping Frequency B Field μ I
Simple Harmonic Motion 0 0 Any Any Any
High Frequency Field 0 50 1 1 1
Damped Harmonic Motion 1 0 5 5 1
Unstable Confinement 0 12 15 1 1
Two Stable Points 2 10 25 1 1
Anti-Damping! -0.1 8 11 1 1


Figure 6: The Damped Harmonic Motion, Unstable Confinement and 2 Stable Points examples with a variety of initial velocities and angles.

Conclusions

We have clearly observed, in a number of cases, chaotic motion dependent on the paramter λ. Since all our calculations involve Bμ/I we could simply have left this as one parameter - in fact I simply leave I and μ as 1 for most of my simulations just altering B. However, all are included as alterable parameters in the simulation for a sense of completeness.

The simulation is successful, and does exactly what it has set out to do - show the chaotic motion of a compass in an oscillating magnetic field. To this I added a few features to make the chaotic nature of the motion more readily apparent.