As I mentioned in the math section, the Runge-Kutta solution has an error factor which increases with the square of the time-step. I ran this program on two different machines, my Pentium at home and the much slower PC's in the EBU2 lab. When I used the slow machines I was forced to use a fairly large time step in order to make the graphic display look realistic. But when I did this, the pendulum would sometimes begin spinning control, gaining a massive amount of energy and becoming impossible to track.
The danger comes from round-off error, especially when the pendulum moves too close to the center and undergoes a large amount of centrifugal force: this force gets highly magnified and ruins the simulation.
So here's a warning. Use whatever time scale makes sense on your machine, but if it starts displaying crazy behavior, then consider going down to a smaller time step; or simply give up on the initial configuration you have chosen and try another.
The program is not designed to read initial values of pTheta and pPhi directly, because finding appropriate values proved to be somewhat unclear and cumbersome. Instead, the program reads values of theta_0, theta_1, and phi_0. pTheta is initialized to 0, and pPhi is automatically set to an appropriate value so that the pendulum will have an initial rotation that keeps it from falling to the center.
There are two reasons for doing this. First, it keeps the user from having to remember an appropriate magnitude for the momentum, which seems quite arbitrary. Second, it usually prevents the pendulum from getting too close to the center, which I mentioned before tends to cause errors.
If theta_1 is set to 0, theta_0 is the constant angle that the pendulum maintains as it rotates around phi. If theta_1 is not 0, the pendulum will bob up and down (because of centrifugal force) with an amplitude of theta_1 with theta_0 as the center. This will be demonstrated in the test cases.
To run the test cases, start the program by typing "magnets 1" or some other number up to 9.
Test case 0 is the default value. It's just an interesting configuration that's kind of fun to watch.
Test cases 1-3 demonstrate behavior of the pendulum with no magnets present (magnet strength has been set to 0 and the magnets are not drawn). In test case 1, theta_0 = 0 and theta_1 = 45, so the pendulum simply swings back and forth with no change in phi, to a height of 45 degrees.
In test case 2, theta_0 = 45 and theta_1 = 45, so the pendulum rotates around phi with a constant theta of 45 degrees. (This is easier to see if you rotate to an overhead view. Experiment with the j and u keys.)
In test case 3, theta_0 = 45 (again) and theta_1 = 15, so the pendulum rotates around while bouncing from a height of 60 degrees down to 30 degrees.
Test case 4 is designed to show you how attractive magnets affect the pendulum. There are three magnets on one side that pull the swinging pendulum towards them.
Test case 5 is designed to show you how repellent magnets affect the pendulum. Three magnets are placed in a roughly circular shape and the pendulum begins with an initial rotation. The repellent force prevents the magnets from falling into the center.
Test cases 6 through 9 were all generated randomly by using the "magnets -r" flag. I simply ran the randomized program many times until I found some configurations that I enjoyed watching.
I strongly encourage the reader to experiment with his own setup. The best method for playing with this program is to use the randomizer to come up with unusual configurations, then write down the numbers and use the input mode ("magnets -i") to try small variations on the same theme.
The pendulum eventually stops because there is a time limit placed on it, for a large variety of debugging and error-control reasons. When it stops, you can still rotate it and admire it from all angles if you wish, but don't expect it to do anything interesting until you press 'q' and then restart. This is not a bug.
Download the program now!
Main magnets page |