up

Artillery and Spring Simulator

Comp259, HW 1

by Jeff Feasel

Assignment

Integration Methods

    I implemented Euler's Method, Midpoint, Runga-Kutta 3, and Runga-Kutta 4.

Numerical Accuracy

    As a means of comparing the accuacy of the integrations methods, I ran the simulation using an extremely small time step with Runga-Kutta 4 integration.  From this, I obtain a so-called "Gold Standard" with which to compare the results of the simulation.  I was interested in the performance of the 4 integration methods (Euler, RK-2, RK-3, RK-4) using a time step of 30 ms, so I chose a timestep of 0.03 ms (one thousanth the size) in order to ensure that the Gold-Standard of comparison was reasonably accurate.
    As an error metric I measure the position of the projectile (in the cannon simulation) or the weight (in the spring simulation) and compare its maximum deviation from the position in the Gold-Standard at any point in the simulation.
    In the cannon simulation, the projectile flew a distance of approximately 100 meters before hitting the ground (25kg of powder used, with the initial velocity computed using a barrel time of 30 ms).  In the spring simulation, the spacial wavelength of the undampened oscillator was approximately 6.5 meters.  The max displacement error in the two simulations is shown below for each of the 4 integration methods.

Artillery Simulation

Integration Method
Error (m)
Euler
0.499
Midpoint
0.00704
RK-3
0.00670
RK-4
0.00652

Spring Simulation

Integration Method
Error (m)
Euler
0.709
Midpoint
0.00948
RK-3
0.00479
RK-4
0.00164


Stability

    Instability in the spring-mass system can be seen in the mass ocilliating beyond its initial release position as the simulation progresses.  In other words, the spring is released from a certain position at time 0, falls due to gravity, and eventually bounces back up to where it started (if damping is turned off).  As time goes on the weight will bounce higher than the initial position, which means that the inaccuracy of the numerical integration has added energy to the system.  Over time, the weight will bounce higher and higher, and eventually the system "blows-up" (i.e. the weight bounces unrealitically high and the simulation can't be considered qualitatively accurate).
    To measure the instability, I set a certain threshold distance above the initial release point.  I ran the simulation for 30 seconds (about 10 oscillations, given the inital conditions) and measured whether or not the weight ever went above this level during the 30 seconds.  I then found the largest timestep for each integration method that will allow the simulation to remain stable (i.e. the weight never goes above the level) for 30 seconds.  The largest time step that gives stability using each of the 4 integration methods is summarized below.  The threshold was set to 0.1 meters above the initial relase point, where the spacial wavelength of the oscillation (while stable) was approximately 6.5 meters.

Integration Method
Largest Stable Timestep (ms)
Euler
62
Midpoint
475
RK-3
633
RK-4
1203

    I found no good measure of stability in the artillery simluation.  The simulation seemed to remain stable (although not necessarily accurate, of course) for all integration methods and for all ranges of parameters that I tried.

Efficiency

    Midpoint, RK-3, and RK-4 seemed to take roughly 2, 3, and 4 times as much time as Euler's Method, respectively.

Code

Here's the source code.  Written in C++, using GLUT.