February 9, 2017 --- Class 10 --- Sources of Numerical Analysis Code,
Final Project, Graphing options, Energy conservation
Activities:
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
Final Project
It is time to start thinking about your final project. Some
of you may have a problem related to your research that can
be used for the project. If not, there may be some problem
that interests you that would serve as a project. If you
don't have an idea of your own, you might like to look through
our text book. If there is a chapter that we will not cover,
you might find some homework problems that can be combined to
make a project. The book also has some suggestions for
projects. Some of these, even in chapters we will (partially)
cover make suitable projects. So start to think about what
you want to do, because in a couple of weeks, I will be asking
everyone to get their project approved by me.
Here is how the final project will be graded:
Statement 10
Eq Solved 5
Num. Method 5
Code 5
Results 10
Discussion 10
Critique 5
------------------
Total 50
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 should make 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.
Graphing energy for different step sizes and two algorithms
Students were asked to prepare graphs showing energy vs. time
for different step sizes with the Euler algorithm. I found
it easiest to concatenate data files for the three step sizes
and edit the file by hand to include labels on the last point
of each curve and add lines for different colors for each curve.
We looked at the file ~sg/chap4/euler_energy.ax which includes
the commands use get the energy from the full output files.
Note that lines that start with # should contain valid axis
commands and a line starting with other symbols can be used to
leave comments in an axis file. I often start comment lines
with a semicolon or exclamation point. My convention is to
end files for graphing with axis with .ax . If is seen
the for the Euler algorithm the energy is rapidly increasing
no matter how small the step size.
Students were asked to graph the energy for both the Euler
and Euler-Cromer algorithms using the same step size. My
solution can be found in ~sg/chap4/energy_both.csh It was found
that with the Euler-Cromer algorithm the energy oscillates
around the correct value.
Energy conservation
File ~sg/sho_energy.pdf contains a derivation of why the
energy is exponentially increasing for the Euler algorith with
the simple harmonic oscillator. You should complete the
derivation for the Euler-Cromer algorithm to understand why the
energy oscillates about the correct value.