r/programming • • Dec 23 '12

Simulating a solar system with Python

http://users.softlab.ntua.gr/~ttsiod/gravityRK4.html
244 Upvotes

72 comments sorted by

View all comments

Show parent comment

8

u/luchak Dec 23 '12

That's not a great article. The author's default timestep, dt=1, is way too large for his simple example: just look at how few frames the object spends close to the "sun", where the forces are largest and velocities highest. This choice of timestep created a number of artifacts in his simulations, which he analyzed very poorly.

The Verlet integrator does in fact preserve energy very well at dt = 1. The Euler integrator blows up almost immediately (as expected), and RK4 loses energy. In fact, I have no idea how he classifies RK4 as the worst of the bunch at dt = 1, since at that timestep Euler blows up and has a precession artifact, while RK4 remains stable (until the object passes way too close to the sun) and mostly avoids the precession artifact.

His analysis is better at the smaller timesteps, but I would think that's because there are fewer artifacts to interpret there.

edit: Looking at his results again, I have no idea how he claims that Verlet integration is "identical" to Euler integration. It's like he didn't even look at his own results.