ODE's & Particle Dynamics



Code for this project is here. Note that the rendering engine comprises the majority of the codebase. The code related to this assignment is in the simulator directory.
simulator code

Binaries for Mac OSX are also available:
simulator binary



Cannon


A simple cannon with adjustible elevation and direction. Variables in the system are the mass of the slug, the amount of gravity, the amount of powder used to fire the slug, the amount of air-drag, and the simulation time step.



cannon case: 1
powder: 1
friction: 50
mass: 100
elevation: 45
gravity: -9.81
step: 0.1

As this case clearly shows, very little error is accumulated when the step size is small. In general, all three integration methods perform reasonably well. While Euler does incur an error penalty due to its single derivative evaluation, it is difficult to cause instability with this simple particle system.

cannon case: 2
powder: 3
friction: 10
mass: 100
elevation: 85
gravity: -9.81
step: 5

As the step size increases, the the distance between derivative estimates increases, greatly increasing the possibility to accumulate error. As seen in this example, Euler's method is quite inaccurate compared to the higher order integration methods. Note that the Midpoint method's local error is beginning to show.




Spring


A spring-mass system. Features adjustible spring constant, mass, gravity amount, drag factor, and step size. The small red disc marks the rest point of the spring system.


spring case: 1
spring constant: 15
drag: 0
mass: 5
step: 0.1

The Euler method diverges very quickly due to the more complex acceleration term. The other methods remain fairly stable.

spring case: 2
spring constant: 20
drag: 0
mass: 10
step: 0.1

A slight alteration in the initial values causes the more oscillation due to the greater mass.




Analysis

Based on the results above, the RK4 method is the most accurate of the three methods as it can handle much larger step sizes without diverging. However, the Midpoint method is remarkably accurate, even with two fewer derivative estimates. Both RK4 and Midpoint are fairly stable, however, due to its higher order approximation, RK4 is more stable than Midpoint.

As to which method is more efficient, it depends on the application. RK4 is capable of evaluating four derivatives in each step, allowing it to solve simulations much faster than the other methods (by taking larger steps). Yet, Midpoint and Euler's require less computation per step, and if an accurate solution is not needed, these methods are quite appropriate (see cannon cases for example).