(adsbygoogle = window.adsbygoogle || []).push({}); [SOLVED] RK4 in solar system simulation (n-body problem)

Hi, i'm making a simulation of the solar system and have so far been using euler's method to integrate my equations of motion - and i'd like to upgrade to a 4th order runge-kutta method.

I'm having alot of trouble understanding the details however:

the acceleration of each body is dependent on the current position of every body.

the position of a body is dependent on its velocity, which in turn is dependent on its acceleration...

Given the general RK4 algorithm:

dy/dx = f(x,y)

y_(n+1) = y_n + (h/4)(k_1 + 2k_2 + 2k_3 + k_4)

k_1 = f(x_n,y_n)

k_2 = f(x_n + h/2 , y_n + (h/2)k_1 )

k_3 = f(x_n + h/2 , y_n + (h/2)k_2 )

k_4 = f(x_n + h , y_n + hk_3 )

do i calculate k_1, then increment the positions x for each object; then calculate k_2 based on that, re-increment the positions x for each object; calculate k_3 .. etc .. then use those approximations in the formula for y_(n+1) and repeat?

if this is how i'm supposed to do it, how the hell is this going to be more efficient than euler's method?

Thanks for your help.

**Physics Forums | Science Articles, Homework Help, Discussion**

Join Physics Forums Today!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

# RK4 in solar system simulation (n-body problem)

**Physics Forums | Science Articles, Homework Help, Discussion**