Calculate the new position at time t of bodies with variable acceleration

celestial-mechanicsmathematical physicsnumerical methodsphysicsvectors

Intro

For an N-body simulation of calestial bodies I need to calculate

  • on the one hand the accelerations of the calestial bodies based on the received gravitational forces [done]
  • and on the other hand the new position of the individual calestial body a time t. [todo].

Problem

How do I calculate the new position at time t of a body with a constantly changing acceleration?

Some additional information

  • The acceleration is computed in step one for all bodies in the system and after calcualting the new position, then it starts from the beginning with the new calculated position and velocity from step 2.
  • For each body I know the mass, the start and current position (from step 2), the initial and current velocity (from step 2), the acceleration (from step 1).

What I have did so far

  • I calculated the current accelerations for each body based on the received gravitational forces.
  • I calculated the new position and velocity based of an constant acceleration which is obivsoulsy wrong, because in each iteration the distance betweens the bodies changes and therefore the recevied force which results in a new acceleration.

Best Answer

For each of the $N$ bodies, define its position as $x_i$ and its velocity as $v_i$, then write the differential equation for $x_i$ and $v_i$ as follows

$ \dfrac{d}{dt} x_i = v_i $

$ \dfrac{d}{dt} v_i = a_i $

Now $a_i = \dfrac{1}{m_i} F_i $

where $F_i = \displaystyle \sum_{ j , j \ne i} \dfrac{ G m_i m_j (x_j - x_i) }{\| x_i - x_j \|^3} $

The state vector of the whole system is defined as

$ x = [x_1, x_2, x_3, ..., x_N , v_1, v_2, v_3, ..., v_N ]^T$

Then you have

$ \dot{x} = f(x) $

And you just have to integrate this vector differential equation numerically, using an accurate method like the Runge-Kutta $4$-th order method. This will give you the position of all the $N$ bodies as a function of time.

Related Question