RK4 in solar system simulation (n-body problem)

  • Thread starter lzkelley
  • Start date
275
2

Main Question or Discussion Point

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

Answers and Replies

275
2
No one has experience with a multi-body, 2nd order RK4?
 
jtbell
Mentor
15,402
3,190
Yes, you've got the right idea. One step of RK4 takes more work than one step of Euler, but the error per step is much smaller. Therefore you can increase the step size, decreasing the amount of work, while still having a smaller total error than Euler. You'll have to experiment a bit to find the "right" step size for your situation.
 
275
2
awesome thanks!
 

Related Threads for: RK4 in solar system simulation (n-body problem)

Replies
1
Views
2K
Replies
7
Views
2K
Replies
13
Views
4K
Replies
11
Views
7K
  • Last Post
Replies
6
Views
994
Replies
3
Views
2K
  • Last Post
Replies
9
Views
807
Replies
4
Views
3K
Top