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".

  • $\begingroup$ Before you can apply the RK scheme, you need a DE. Where is your DE? How would you construct a DE from those two laws? P.S. Apparently you're using electrostatic units based on the form of Coulomb's law you mention; make sure your units are consistent! $\endgroup$ – J. M. is a poor mathematician Dec 20 '10 at 12:37
  • $\begingroup$ The differential equation is $m\frac{d^2 \vec{r}}{dt^2}=\frac{q_1 q_2}{r^3}\vec{r}$. This gives the relative motion of the bodies. $\endgroup$ – Raskolnikov Dec 20 '10 at 12:48
  • $\begingroup$ If you use @Raskolnikov's formulation, note that you have a vector DE; for this, one applies RK (or any other DE-solving scheme for that matter) componentwise. $\endgroup$ – J. M. is a poor mathematician Dec 20 '10 at 12:53
  • $\begingroup$ The main problem is that for unlike charges, the force is attractive, thus reducing the distance between the particles. The acceleration grows inversely as the square of the distance, which means that close to the singularity of the force (or potential), your predictions will be inaccurate. $\endgroup$ – Raskolnikov Dec 20 '10 at 13:07

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.

  • $\begingroup$ Is there a list of higher order versions? I know of leap-frog method. $\endgroup$ – Maesumi Jun 29 '13 at 12:54

Write $u(t)=(x(t),v(t)$, where $x$ is the position and $v$ is the velocity. Then Newton's law implies $u' = (v,F/m)$. That's your differential equation, and you can apply RK to it.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.