This is a sample code for integrating ordinary differential equations using Adams-Bashforth formulae with adaptive step size and order. All compilable code here is written in Fortran 90. For assistance with running this code, contact the author, Daniel Steck, at . This code is provided as-is, without warranty; you should thoroughly test it before trusting it. This code is free for non-commercial use. This is version 1.0 of this integrator. ************************************************************************ The contents of this directory are: README: this file odeab90.f90: the file containing the integrator module hosc.f90: a sample driver for odeab90.f90 to integrate a problem with a known analytic solution globals.f90: defines global variables to be shared by multiple routines odeab_support.f90: integrator support module, defining the equations of motion for the problem, and interface stuff for odeab90. utilities.f90: general-use utilities (hosc uses 's2r' to convert strings to real numbers) Makefile: makefile for test1.f90, this tells the 'make' utility what to do ************************************************************************ To modify this code to solve other problems, you will want to concentrate on 'hosc.f90' and 'odeab_support.f90'. Read the extensive comments in the source files to see what is going on. ************************************************************************ NOTE: this integrator is written by me and has not been tested by a large user community for many years. It is a sophisticated Adams- Bashforth code with adaptive step size and adaptive integration order. It should be high-quality and efficient, but there is always the possiblity for finding a bug. Normally, I would recommend a production-quality integrator such as ODEPACK, but I am building this example around this integrator so you can have a portable, self-contained code. This is particularly important in this course since we don't have a specific "home" cluster. ************************************************************************ To try this out: download the source tarball, by using "download as" in your browser or by using wget: wget where is the location of the source tarball odesample.tgz, something like wget atomoptics.uoregon.edu/~dsteck/teaching/07spring/phys686/odesample.tgz Now unpack it: tar xvzf odesample.tgz Enter the unpacked directory: cd odesample Build the source: make Try running it: hosc You should have gotten usage info. Try a simulation: hosc 1 5 0.01 10 (What do the numbers mean? Look at the usage info!) You should have gotten a bunch of output, and some run-time diagnostics. Do it again, but save the data to the file 'out.txt': hosc 1 5 0.01 10 > out.txt Now plot it in gnuplot. Make sure X Windows is running, then type gnuplot Inside gnuplot, try this: plot 'out.txt' using 1:2 with lines You should get a plot of the integrator solution. Compare it to the analytic solution by doing this: plot 'out.txt' using 1:2 with lines, 'out.txt' using 1:3 with lines You shouldn't be able to see the difference, because the numerical solution is very accurate. How accurate? Plot the difference: plot 'out.txt' using 1:($2-$3) with lines Pretty accurate! Now make this last plot pretty: set title 'My nice error plot (y0=1, omega=5)' set xlabel 'error' set ylabel 'time' replot Suppose you want to print the plot out so you can frame it and hang it on the wall for all your friends to see. Let's make a postscript file out of it, 'out.ps': set terminal postscript color set output 'out.ps' replot set terminal x11 The last bit prevents you from writing more to the file. Now use gs to view the file (gs out.ps), or make a pdf out of it, 'out.pdf': ps2pdf out.ps On a mac, you can look at it in Preview.app: open out.pdf To include this file in a LaTeX file (though you should really make a nicer plot than this!), you could convert it to an .eps file: ps2eps -l out.ps which gives you 'out.eps'. This is assuming ps2eps is installed (it is on my lab computers.) By the way, if you want to delete all the object (.o) and executable files after you're done, type make clean This is also useful for force compilation over from scratch. ************************************************************************