Mathematical Solution

Acknowledgement: I would like to take this opportunity to thank my father, Alan Glasser, a physicist at Los Alamos, for the invaluable support he provided in helping to derive the equations in this section.


Physical Model: Hamilton's Equations

The magnetic pendulum can be described by a set of first order differential equations. For convenience, we define the parameters of the pendulum in terms of spherical coordinates Theta, Phi and R. Since R (the length of the pendulum) is constant, the variables that we deal with in this problem are Theta, Phi, pTheta, and pPhi, where pTheta and pPhi represent the momentum in the direction of angles Theta and Phi. Theta is the angular offset from 0 (pendulum pointing straight down) and Phi is the rotation about the vertical axis.

These are time-dependent variables which can be calculated using Hamilton's equations, a general method for computing position and momentum as a function of time. Since the total energy of any system remains constant over time, the Hamiltonian function indicates that the total energy H is always

qi is a vector of the position components; in this case it is a two-dimensional vector with Theta and Phi as components. pi is the momentum vector. T and V represent the kinetic and potential energies, respectively.

The solution to Hamilton's equations is a pair of first order differential equations

        d q_i     dH      d p_i       dH
        ----- = -----  ,  ----- = - -----
          dt    d p_i       dt      d q_i
Now, we can show that
	dTheta	 p_Theta
	------ = -------
	   dt	  m*l^2
where m is the mass of the pendulum (assumed to be a point mass concentrated in the tip), and l is the length. The change in phi is
        dPhi        p_Phi
        ---- = ----------------
         dt    m*l^2*sin(Theta)

These are the first two Hamiltonian equations. The differential equations for pTheta and pPhi are a bit trickier to compute, and so I will not present the entire derivation in this report (because the focus is supposed to be on graphics). Instead, I will just show how the equations are set up and then move on.

The kinetic energy is a function of pseudo-forces that arise from polar coordinate notation, i.e., centrifugal force and coriolis forces.

        
        d p_Theta   p_Phi^2*cos(Theta)     dV
        --------- = ------------------ - ------
           dt       m*l^2*sin^3(Theta)   dTheta

        d p_Phi       dV
        ------- = - ------
           dt       dTheta
V is the potential energy, which is affected by gravity and the forces from each magnet. In polar notation, the force of gravity is m*g*l*cos(Theta). The force exerted by each magnet is 4*m1*m2/d3, where m1 and m2 are the magnetic strengths of the base magnet and the pendulum's magnet. Since m1 and m2 do not change throughout the problem, and each base magnet is assumed to have the same strength, we just define a constant "strength" representing 4*m1*m2.

d, of course, is the distance from the pendulum to any base magnet. Notice that the force falls off proportionate to the cube of the distance, which explains the extremely erratic behavior of the pendulum as it passes through each magnetic field.

To obtain the remaining Hamiltonian equations, it is necessary to sum the forces and take their derivative. Since this was a task that my father dealt with, I will leave it as an exercise for the reader. ;)


Solution For Differential Equations: Runge-Kutta

Once we have obtained a set of ODE's, we apply the Runge-Kutta method to solve for the changing position of the pendulum. By the Runge-Kutta method, given an ODE of the form

where y is a vector (in this case with four components theta, phi, and their respective momenta) and t is time, the solution is What this method does is input a set of parameters (y) at time t, and output the parameters at the next time step -- the size of the time step being defined by h.

Runge-Kutta's accuracy depends to a large degree on the size of the time step. As h increases, the potential error increases in propotion to the square of the time step size. Therefore, this program suffers some severe limitations when time steps larger than about 10-3 are applied. I will discuss this problem further in the miscellaneous information section.

 


User manual

Main magnets page