0

I am trying to program a $n$-body problem simulation. To calculate the position and velocity after a time-step I want to split it in multiple 2 body problems. Now I am stuck, trying to find the velocity and position of two bodies (ignoring all the others) after one time-step with given mass, start position and velocity.

I am able to calculate the force between the two, but I am unable to solve the differential equation $$ \ddot{\vec{r_{12}}(t)} = G M \frac{\vec{r_{12}(t)}}{|\vec{r_{12}(t)}|^3} \\ M := m_1 + m_2 \\ \vec{r_{12}(t)} := \vec{r_1}(t) - \vec{r_2}(t) $$

to calculate the position relative to each other. What is $\vec{r}(t)$ and how can I calculate it? And is there another and maybe faster way to get the positions and velocities?

Edit: As @Sofia pointed out, this was not clear: $\vec{r_1}$ and $\vec{r_2}$ are the location vectors of the two masses.

Marcy
  • 103

1 Answers1

1

Now I am stuck, trying to find the velocity and position of two bodies (ignoring all the others) after one time-step with given mass, start position and velocity.

You get the final velocity at impact $v$ with

$$v=\sqrt{\int_{r_1}^{r_2} \left(\frac{2 G M}{r^2}+\frac{v_0^2}{r_1-r_2}\right) \, \text{d}r}$$

Where $r_2$ is the initial distance and $r_1$ the final (so if you yould have the moon falling on the earth $r_2$ was the distance from center to center and $r_1$ the radius of the earth plus the radius of the moon.

If you want the velocities at a specific distance in free fall just replace your $r_1$ with the distance you need.

The time $t$ until mass A hits mass B is

$$t=\int_{r_1}^{r_2} \frac{1}{\sqrt{2 G (M_1+M_2) \left(\frac{1}{r}-\frac{1}{r_2}\right)+v_0^2}} \, \text{d}r$$

Those are the analytical solutions. If you want to solve it differentially you need to go numeric. In the following example you have 2 point masses separated by a distance of 6371 km, one the mass of the earth and the other the mass of the moon. They will meet in 889 sec and the heavy mass will move x = 77 km in the right, and the light one R-x in the left direction. If you want to solve for velocity or acceleration at time t just replace x1[t] by x2'[t] or x1''[t]:

solution

I am trying to program a n-body problem simulation

You can also check out my 4 Body simulations at http://yukterez.ist.org/3kp/3k3D.html, http://yukterez.ist.org/4kp2 and http://bit.ly/1aMbgGH - the code is more or less self explaining.

Yukterez
  • 14,655