PHYS 252

Always hand in:
  1. written solutions to any questions
  2. a paper print-out of well-commented code. Include a multiline comment at the top of your code with (i) the assignment name, (ii) your name, and (iii) the date you handed in all elements of the assignment
  3. paper print-out of output (graph or text)
  4. also, e-mail me (y-lithwick@northwestern.edu) the code with your name and the exercise number in the subject line

Assignment #6
[5pts, due 2pm, April 17]

  1. 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.

  2. [For #2, you have the option of doing either the question below, or question 3.4 in the book]

    Evaluate the accuracy of two integration methods from question 1 by plotting the fractional error in θ(t=1000) as a function of Δ t. You may choose which two methods you'd like to consider. How does your code's error scale with Δ t, and how is it supposed to scale with Δ t?

    Note: You should output θ as close as possible to t=1000 (to many significant figures).