Some messing around with n-body simulations (very casual) 1/16/19


Using MATLAB, I wrote a simple equal mass 3-body system simulation. There are several options for the method of integration, I tried out these four: (Let $a(r)$ be the acceleration of the body when it has the position vector $r$, and $a,v,$ and $r$ are all vectors and $h$ is the time step) (In my algorithm I calculate acceleration using Newton's law of gravity assuming $G,M=1.$) My understanding of the math isn't really good enough to explain why one is better than the other, so I decided to test them against each other for a few cases. Since the 3-body system is chaotic, the accuracy of the model matters quite a lot. Here is a table comparing these 4 integration methods at different time-steps:

Full size. The initial conditions were: As you can see, there is a lot of difference. This is because the initial conditions were set up for three "close encounters," and these have the tendency to magnify any deviations. The behavior of the system is pretty hard to predict mostly for that reason.

The accuracy of each method can be tested against the simple case of a mass orbiting another, stationary, mass.

Full size. Key: green - correct orbit (circle); red - Runge Kutta; blue - leapfrog; blue* - midpoint; red* - Euler.

Initial conditions were $r=(-1,0,0),v=(0,1,0).$ Iterated over a time of 10 seconds with timestep 0.3 seconds. Here it's clear that the Runge-Kutta method has the least error. However, the leapfrog method has the advantage of remaining in a stable orbit, whereas the Runge-Kutta method tends to decay:

Full size. Initial conditions: same as above. Iterated over a time of 10000 seconds with timestep 0.3 seconds.

An obvious next step is to look for some nicely periodic, bounded systems. Here is one I stumbled upon:

Initial conditions: $r_a=(0,0,0), v_a = (0,-1.5,0), r_b = (0.5,0,0), v_b = (0, 1.5, 0), r_c = (1,0,0), v_c=(0,0,0)$


I am not sure if the exact configuration remains periodic in the long term, because the simulations show that it explodes eventually:

(Calculated with the leapfrog method for timestep 0.001 and total time 100, with initial conditions as specified above.)