PHYSICS 141/241

Winter 2020

Assignment I.

Due date: 1/24/2020

To prepare for your first code, you might want to download and modify a sample program. The source code is available in C (leapint.c). To compile the program, try to use the command

 % gcc -o leapint leapint.c

after you located the path to the compiler. Sometimes gcc requires the -lm linking of the math libraries during compilation: gcc -lm -o leapint leapint.c. To run the compiled program, use the command
 % leapint

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.

Problem 1 (141/241)

(a)  Modify the statements which set up initial conditions in the main program to produce trajectories starting from the points (2,0) and (0,3). On the (x,v) plane, plot these trajectories (gnuplot, or your favorite plotting platform) 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), & (0,3).  241 only: animate the phase space motion for the three trajectories simultaneously.

(c)   241 only: animate the phase space motion for the three tarjactories simultaneously.

(d)  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).


Problem 2 (141/241)

(a)  Write leapfrog code (or some other equivalent 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.


Problem 3 (141/241)

(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.

(c) 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 on Kepler orbits. Generalize the proof to general spherically symmetric potetials.


Problem 5  (for Physics 141/241)

Calculate and plot the orbit of the Halley comet (read about the comet and its orbit in Wikipedia).

Problem 6  (for Physics 241 only)

Put the Halley comet and Earth in the same animation and demonstrate one full Halley year.

(Halley comet in Wiki)

Comet table:

(comet table)


Tutorial for Leapfrog Integration


Tutorial on Kepler orbits



Added reading material for Assignment I


2d leapfrog link

Verlet-Notes pdf file

Kepler error illustrations pdf file