[Math] Runge-Kutta method for Newton law

numerical methodsordinary differential equations

I'm trying to make one body fly around another, using Coulomb law $F=\frac{q_1 q_2}{r^2}$ and second Newton law $ma=F$. Now I'm doing it this intuitive way:

  1. Move body1 according to current speed and $dt$;
  2. Calc new Coulomb force then find acceleration $a=\frac{F}{m}$;
  3. Add acceleration to current speed;
  4. Repeat.

This works fine. I know this is very simple Euler method and it's very inaccurate. I'd like to use Runge-Kutta method, but I can't figure out how I should implement it. Here it's described, but

  1. What is my $f(x, y)$?
  2. What is my $y'$ and $y''$?
  3. Where $dt$ goes?

Thank you.

UPD. Thanks for help! Also I've found this nice little article that was quite helpful. Can't insert direct link, but it's first result if google "Many-Body Gravity Simulation Using Multivariable Numerical Integration".

Best Answer

I wanted to note that the method you are using is not foward Euler. What you are doing is:

$$v(t+\delta t) = v(t) + \delta t \cdot a(t) $$ $$x(t+\delta t) = x(t) + \delta t \cdot v(t+\delta t)$$

which is called symplectic Euler method, and has much better convergence properties than the standard Forward Euler method. Forward Euler would be:

$$v(t+\delta t) = v(t) + \delta t \cdot a(t) $$ $$x(t+\delta t) = x(t) + \delta t \cdot v(t)$$

For your answer, the trick is indeed to consider the velocity as a final variable of your system and write what @lhf said:

$$u(t) = (x(t), v(t))$$ $$u' = (v, F/m)$$

You have to solve a single system with six equations per points now. But each equation is only a first order ODE.

Related Question