PHYSICS 141/241

Lecture 2: Newton equations and numerical analysis

 

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 C (leapint.c) and in C++ the leapfrog code snippet (Leapfrog code). To compile the C program, use the terminal command: gcc -o leapint leapint.c
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 and reading material on ODE time integration

ODE Integrators (very useful reading material)

Error analysis (advanced background material)

Leapfrog code