Consider the free undamped pendulum,
with equation of motion
(i.e., setting g/l=1).
Now integrate the equation of motion with
four different algorithms: Euler, Euler-Cromer,
2nd-order Runge-Kutta (RK2), and
4th-order Runge-Kutta (RK4), and plot the energy
as a function of time for each algorithm.
(The energy is
E(t) = (1/2)(dθ/dt)2 + (1-cosθ).
Can you show [not for credit] that the equation of motion
conserves energy?)
Choose initial conditions so that the
pendulum is oscillating (not swinging
around in circles), and an
integration timestep Δ t= 0.01.
Comment on your
result. Make sure you run for sufficiently
long t to draw valid conclusions.
Note: the Runge-Kutta formulas are given
in Computational Physics,
equation A.7 (RK2) and A.9 (RK4).
If you use integ.c from Assignment
4 as a guide, (or else my version integ2.c in Supplementary
Info), I recommend
that you modify the step routine for
each algorithm, and keep the four functions
"stepEuler", "stepEulercromer", "stepRK2", and "stepRK4".
You can then use these functions in future
work for different equations of motion.