RK4 in solar system simulation (n-body problem)

AI Thread Summary
The discussion centers on upgrading a solar system simulation from Euler's method to the 4th order Runge-Kutta (RK4) method for solving the n-body problem. The main challenge highlighted is the interdependence of the positions and velocities of the bodies due to their mutual gravitational influences. The RK4 algorithm is explained, emphasizing the calculation of intermediate values (k_1, k_2, k_3, k_4) to update the positions and velocities. It is noted that while RK4 requires more computational effort per step compared to Euler's method, it offers significantly reduced error per step, allowing for larger step sizes and overall decreased computational workload while maintaining accuracy. Experimentation with step sizes is encouraged to optimize performance.
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!
 
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I have a quick questions. I am going through a book on C programming on my own. Afterwards, I plan to go through something call data structures and algorithms on my own also in C. I also need to learn C++, Matlab and for personal interest Haskell. For the two topic of data structures and algorithms, I understand there are standard ones across all programming languages. After learning it through C, what would be the biggest issue when trying to implement the same data...

Similar threads

Replies
2
Views
3K
Replies
15
Views
3K
Replies
1
Views
3K
Replies
19
Views
4K
Replies
7
Views
3K
Replies
4
Views
2K
Back
Top