September 25, 2007 --- Class 9 --- Oscillatory Motion, Script writing, Conservation of Energy in the Euler Algorithm Activities: Chapter 4---Oscillatory Motion We used the code ~sg/chap4/sho2.c and executable sho2 to calculate the motion of a simple harmonic oscillator. This code is based on the Euler method. We found that energy is not conserved. In fact, we found that the energy grows exponentially with time, no matter how small the integration step size. With the Euler-Cromer algorithm, the energy varies during the motion of the body, but it is not monotonically increasing as it is for the Euler method. It was very easy to demonstrate this by making a few changes to the script used to run the euler code. The error is order dt for these methods, but the Euler method is unstable, i.e., the errors grow with time. For homework #3, the Euler-Richardson and Runge-Kutta methods will be used. A Script to Find the Position as a Function of Step Size We wrote a script to run sho2 for different step sizes and to find the value of the position after one or two seconds. We were then able to plot the results to see that the error is linear for small dt. Here is a script x_vs_dt.csh that you can find in ~sg/chap4 #!/bin/csh # script to plot position at t= 1s vs dt foreach dt ( .1 .05 .01 .005 .001 .0005 ) echo -n $dt " " sho2 <