ODE's and Particle Dynamics


In this assignment, we had to implement simulations of ballistic motion and spring-mass systems. We were to implement these simulations using multiple numerical integration techniques. In particular, I implemented the Euler, Midpoint, and fourth order Runge-Kutta integration algorithms.

I tested each simulation out with the different integration techniques at different time steps to get a feel for their accuracy, efficiency, and stability. Below are several links to graphs of different simulations:

Ballistic motion

In each of these cases, there were 10kg of powder (1kg generating 10000J of kinetic energy), the particles had mass 50kg, drag was 50kg/s, cannon elevation was 45 degrees, and the cannon azimuth was 0 degrees.

From these graphs, RK4 seems to be the most accurate integration method. For many different time steps, it follows essentially the same path and is close to an analytical solution. On the other extreme, Euler integration works quite well at low time steps, but as the size of the time steps increases, the trajectory of the particles stray considerably from the expected path. The Midpoint method lies somewhere in between these two methods, and seems to be a viable trade-off between efficiency and accuracy. Note that it appears that at low time steps, the performance of the Midpoint and RK4 methods is very close.

Spring-mass system

In each of these cases, the particles had mass 5kg, and the springs had spring constant 15kg/s2, damping factor 1kg/s, and rest length 4m.

The spring-mass system allows us to examine the stability of the different integration methods. At low time steps, all three methods perform approximately just as well, at least for the given physical conditions (different masses/spring constants, etc. might cause certain methods to blow up). At higher time steps, however, there is a vast difference in stability. In particular, the RK4 method is very stable even at a time step of 1.0s, while the Euler and Midpoint methods do not fare so well. At a time step of 0.1s, Midpoint and RK4 perform about the same, but Euler is already out of the question, as its numerical instability causes the mass to oscillate out of control.

The graphs below show the stability of each integration method is affected by changing the time step:

As for efficiency, RK4 (requiring 4 derivatives) is clearly slower than Midpoint (requiring 2 derivatives) and Euler (requiring only 1 derivative). In these small systems, this does not matter much, but in systems where thousands of particles need to be simulated, this may become an issue. It seems that for reasonable time steps, the Midpoint is a nice alternative to RK4 in terms of accuracy. If speed is really required, however, Euler integration is the way to go, but at the expense of accuracy and stability.

Implementation

The code was implemented in VC++ using GLVU and GLUI. It can be downloaded here. Here are a couple of screenshots of the program in action: