Computational Physics, 1B, Term 2

Worked solution for PLANET example

| README | Planet.cc | gnu | gnu10 | gnu11 | sun | Planet2.cc | gnu20 | gnu21 | planet/gnu0 |

Planet.cc is a worked solution for the task:
Write code that implements the Leapfrog method. Get it going for one initial condition, such as x0 = (1.5,2), v0 = (0.4,0).

Every few iterations it prints out
t, x1, x2, v1, v2, T, V, T+V
where T is the kinetic energy and V is the potential energy. When it's printed all those outputs to a file, you can plot things from the file using gnuplot.
Directories: The first C++ program, Planet.cc, will put its output in a directory called planet. The file sun should be in that directory too. I think the "gnu" files (gnu | gnu10 | gnu11) go in the upper directory.
[an error occurred while processing this directive]

gnu is a simple gnuplot file for plotting the output of Planet.cc. It displays the positions and the velocities in a single graph.

[an error occurred while processing this directive]

gnu10 and gnu11 are a fancier pair of gnuplot files for making a movie from the output of Planet.cc. gnu10 sets things up, then calls gnu11, which does the plot and calls itself recursively.

[an error occurred while processing this directive]

[an error occurred while processing this directive]

The file sun contains the coordinates of the sun
[an error occurred while processing this directive]
example1

Planet2.cc is a much fancier solution for the task. It can handle either of two force laws (inverse square and Hooke law); and while it is running, it can print out gnuplot commands to stdout, so if you pipe its output into gnuplot, it makes a live movie. It can be modified so that it performs an Euler simulation immediately after a Leapfrog one. These extra features are not very elegant.
Directories:
For the second program (Planet2.cc), "planet/gnu0" should go in the planet directory. The output of the program is written to files in the "/tmp" folder, and commands for gnuplot are written to standard output (stdout). See the head of the cc file for instructions.
[an error occurred while processing this directive]

David MacKay
Last modified: Wed Nov 14 10:11:32 2007