February 9, 2012 --- Class 10 --- Oscillatory Motion, Conservation of
Energy in the Euler Algorithm, Sources of Numerical Analysis Code,
Higher Order Algorithms
Activities:
Chapter 4---Oscillatory Motion
We used the code ~sg/chap4/sho2.c and executable sho2 or
output from prior running 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.
We made plots of the energy as a function of time and
the position as a function of time. We also wanted to
contract the Euler algorithm with the Euler-Cromer algorithm,
so we made a single graph comparing the energy from each
algorithm using the same 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.
See file ~sg/chap4/energy_0.0125.ax
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.
Conservation of Energy in Euler algorithm
By calculating the energy after a single step for the
harmonic oscillator, we were able to show that for the Euler
algorithm the change in energy is proportional to the
current energy, thus it is increasing exponentally. For
the Euler-Cromer algorithm, the change in energy is
proportional to the difference between potential and
kinetic energy. (This should be derived by the student.)
Since for a harmonic oscillator the time
average of kinetic and potential energies is the same, the
Euler-Cromer algorithm conserves energy on average, i.e.,
the energy ocsillates around the correct mean value.
Some graphing options
Axis has useful options to break lines, label lines and
add color to the plot. I demonstrated several of these
in the file ~sg/chap4/euler_energy.ax. This graph shows
how the energy grows when using the Euler algorithm and three
different step sizes. Students made a similar graph but
for the Euler-Cromer algorithm. In that case, the energy
does not grow, it oscillates around the correct value.
The amplitude of oscillation decreases when the step size
decreases.
Sources of Numerical Analysis Code
So far, we have built our own codes from scratch; however,
you will probably find it very useful to make use of
standard codes that are already debugged. Two good sources
of code for numerical analysis are the book "Numerical
Recipes" (which is recommended for this course) and the GNU
scientific library.
GNU scientific library can be found at:
http://www.gnu.org/software/gsl
Code from Numerical Recipes is not so freely available. But
older versions of the text and source can be found here:
http://www.nrbook.com
The latest version of the book and information about electronic
access are here:
http://www.nr.com
Higher order algorithms
In our next class, we will talk about higher order algorithms.
These have much to recommend them.
My notes can be found at
http://www.physics.indiana.edu/~sg/p609/ode_algorithms.pdf