PHYSICS 141/241

Lecture 2: Overview of Newtonian dynamics

 

PDF file of Lecture 2:

Lecture2.pdf

 


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.c
% g77 -o leapint leapint.f
depending 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
 % 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.

 


Tutorials on ODE time integration

Leapfrog Integrator

Euler method

Runge-Kutta Integrator

Leapfrog code