RK4 in solar system simulation (n-body problem)

  • Thread starter lzkelley
  • Start date
  • #1
lzkelley
277
2
[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 a lot 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

  • #2
lzkelley
277
2
No one has experience with a multi-body, 2nd order RK4?
 
  • #3
jtbell
Mentor
15,940
4,607
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.
 
  • #4
lzkelley
277
2
awesome thanks!
 

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

  • Last Post
Replies
19
Views
1K
Replies
6
Views
964
Replies
6
Views
1K
  • Last Post
Replies
9
Views
2K
  • Last Post
Replies
4
Views
1K
  • Last Post
Replies
7
Views
2K
  • Last Post
Replies
3
Views
935
Replies
15
Views
994
Replies
3
Views
4K
Top