RK4 in solar system simulation (n-body problem)

Click For Summary

Discussion Overview

The discussion revolves around the implementation of the 4th order Runge-Kutta (RK4) method for simulating the solar system, specifically addressing the n-body problem. Participants explore the integration of equations of motion and the dependencies between acceleration, position, and velocity of celestial bodies.

Discussion Character

  • Exploratory, Technical explanation, Debate/contested

Main Points Raised

  • The original poster seeks clarification on how to apply the RK4 method in the context of a multi-body simulation, noting the interdependencies of acceleration, position, and velocity.
  • Some participants confirm that the proposed approach of calculating k_1, then updating positions for each object before calculating k_2, and so on, is correct.
  • One participant mentions that while RK4 requires more computational effort per step compared to Euler's method, it offers a smaller error per step, allowing for larger step sizes and potentially less total computational work.

Areas of Agreement / Disagreement

There is some agreement on the approach to implementing RK4, but the discussion includes uncertainty about the efficiency comparison with Euler's method and the optimal step size for the simulation.

Contextual Notes

The discussion does not resolve the specifics of how to balance computational efficiency with accuracy in the context of the n-body problem, nor does it clarify the assumptions underlying the choice of step size.

lzkelley
Messages
276
Reaction score
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.
 
Technology news on Phys.org
No one has experience with a multi-body, 2nd order RK4?
 
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.
 
awesome thanks!
 

Similar threads

  • · Replies 14 ·
Replies
14
Views
3K
  • · Replies 2 ·
Replies
2
Views
4K
  • · Replies 15 ·
Replies
15
Views
3K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 19 ·
Replies
19
Views
5K
  • · Replies 22 ·
Replies
22
Views
3K
  • · Replies 7 ·
Replies
7
Views
4K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 7 ·
Replies
7
Views
2K