I thought it would be educational (for me if no one else) to look at how some different integration methods perform for different step sizes.
So I set up a simple simulation of an asteroid following an elliptical orbit around a star, and ran it for a range of different sizes of time step. The simulations cover the length of time that the asteroid would take to complete one period of the orbit in the exact solution. So, if a simulation were perfectly accurate, the asteroid would end up exactly back at its starting point. I’m taking the distance of the asteroid from its starting point at the end of the simulation as the measure of a simulation’s error.
The asteroid starts at distance 1.0 from the star, and that’s also its maximum distance (for the exact orbit). So an error of 0.01 at the end of the simulation would probably be acceptable, although of course we’d like to do better than that. If the error is greater than 1 then the simulation was a complete mess.
The simulations run for different numbers of time steps. If T is the time simulated (i.e., one period of the exact orbit) and the simulation performs N time steps, then the size of each time step is dt=T/N.
Here are some plots showing the final error when different numbers of time steps are used. The plots cover the Euler method, the semi-implicit Euler method, and the fourth-order Runge-Kutta method. I also tried the basic Verlet and velocity Verlet methods, but the results were so similar to those of the semi-implicit Euler method that they’re not worth showing.
http://www.dishmoth.com/fig1.png
http://www.dishmoth.com/fig2.png
http://www.dishmoth.com/fig3.png
Clearly the Euler method needs a very large number of very small time steps in order for the error to be small. The semi-implicit Euler method gets away with a lot fewer time steps, and the Runge-Kutta method fewer still.
The difference in performance is clear when the error graphs are plotted all together with logarithmic axes.
http://www.dishmoth.com/fig4.png
For this plot it’s interesting to note that, when the number of time steps gets large enough, the slope of the Runge-Kutta curve is roughly -4, the slope of the semi-implicit Euler curve is roughly -2, and the slope of the Euler curve is roughly -1. This is evidence that the methods converge at fourth order, second order and first order respectively. Curiously, the semi-implicit Euler method is, like the Euler method, only supposed to converge at first order (whereas the Verlet methods converge at second order) so for this problem at least it’s performing better than advertised.
In conclusion, the Euler method isn’t worth bothering with for this problem. The semi-implicit Euler method (which is almost identical) is much better, but in terms of accuracy the Runge-Kutta method wins. That said, it takes a few times more work to perform each step of the Runge-Kutta method, and it’s harder to code, so unless you’re chasing very high accuracy it may not be worth the effort. (In effect, the green curve in the logarithmic plot should be shifted a bit to the right to account for the extra computational work involved.)
All this is just for one example orbit of course. The number of time steps needed to get decent accuracy will be different for different orbits, and will probably depend quite a lot on how close the orbit gets to the star.
I do some strange things for fun sometimes…
Simon