Take the 2-minute tour ×
Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

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

share|improve this question
    
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! –  J. M. Dec 20 '10 at 12:37
    
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. –  Raskolnikov Dec 20 '10 at 12:48
    
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. –  J. M. Dec 20 '10 at 12:53
    
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. –  Raskolnikov Dec 20 '10 at 13:07

3 Answers 3

up vote 5 down vote accepted

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.

share|improve this answer
    
Is there a list of higher order versions? I know of leap-frog method. –  Maesumi Jun 29 '13 at 12:54

Just to be sure in this website http://mathworld.wolfram.com/Runge-KuttaMethod.html f(xn,yn) would be u'(v,F/m) in our case?

If we are given the initial position and velocity then how can I utilize that in u'?

share|improve this answer
    
I want to model the position of a body using a runge kutta method –  erick Apr 11 '13 at 19:21

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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