Due date: 1/31/2013
To prepare for your first code, you might want to download and modify a simple numerical program. The source code is available in either C (leapint.c) or Fortran 77 (leapint.f). To compile the program, give either of the commands
% gcc -o leapint leapint.cdepending on which language you are using. Sometimes the gcc requires the -lm linking of the math libraries during compilation: gcc -lm -o leapint leapint.c. To run the compiled program, give the command
% gfortran -o leapint leapint.f
The output consists of four columns, listing (1) time, (2) point index, (3) position x, and (4) velocity v. Running the program as supplied yields the trajectory of a point starting at (X0,V0) = (1,0) in the phase flow defined by the `linear pendulum' or harmonic oscillator, a(x) = -x. The total number of steps taken, number of steps between outputs, and timestep used are determined by the parameters mstep, nout, dt, respectively; these parameters are set in the main procedure of the program.
(a) Modify the statements which set up initial conditions in the main program to produce trajectories starting from the points (2,0) and (3,0). On the (x,v) plane, plot these trajectories (gnuplot) together with the one starting from (1,0).
(b) Replace the linear pendulum in the accel routine with the "inverse linear pendulum", a(x) = x, and again plot trajectories starting from the points (1,0), (2,0), & (3,0).
(c) Plot trajectories starting from the same three points for the "nonlinear pendulum", a(x) = - sin(x).
Make two-dimensional (x,v) plots and three-dimensional (x,v,t) plots for (a), (b), and (c).
(a) Write leapfrog code (or some other equivalnet finite step integrator) for Mercury,Venus, Earth, Mars, Jupiter, Saturn, Uranus, Neptune, Pluto, orbiting around the Sun. Put the Sun at the origin of your coordinate system. Do some web based research for setting up the initial conditions to have realistic scales of the orbits. Ignore the interactions of the planets in the time integration and keep the Sun fixed at the origin.
(b) Make a composite plot of all the planetary orbits you calculated.
(a) Compare your numerically integrated orbits to the analytic form of the elliptic orbits. Investigate the error behavior over several revolutions of the planets. Do you detect a deterioration with each revolution?
(b) For each planet, plot the numerically integrated orbit and the analytic elliptic orbit on the same plot. Each planet will have its own plot. Plot the error over a full revolution for each planet.
(c) Can you do a simple animation of the earth motion in gnuplot or some other plotting method of your choice?
Problem 4 (for Physics 241 only)
Prove the exact conservation of angular momentum of the discretized leapfrog Verlet algorithm in spherically symmetric potentials.
2d leapfrog link