- #1
pretzsp
- 4
- 0
Homework Statement
Implementing the 4th order Runge-Kutta method for an n-body problem
Homework Equations
The RK4 method for the IVP y' = f(t,y), y(t0) = y0, is given by
y_(n+1) = y_n + (1/6)(k1 + 2 k2 +2 k3 + k4)
t_(n+1) = t_n + h
where
k1 = h f(t_n,y_n)
k2 = h f(t_n+ h/2, y_n + k1/2)
k3 = h f(t_n+ h/2, y_n + k2/2)
k4 = h f(t_n+ h/2, y_n + k3)
The Attempt at a Solution
I'm trying to simulate some n-body problems using the Runge-Kutta 4th Order method on Mathematica. I have something that works, for just the most simple problem of one body orbiting about a fixed mass.
step[data_] := (
t = data[[1]]; kx1 = data[[2]]; kx2 = data[[3]]; kx3 = data[[4]]; kx4 = data[[5]]; kv1 = data[[6]]; kv2 = data[[7]]; kv3 = data[[8]]; kv4 = data[[9]]; v = data[[10]]; x = data[[11]];
{t + h,
h ((1/m2) GravForce[m1, {0, 0}, m2, x]),
h ((1/m2) GravForce[m1, {0, 0}, m2,
x + k1/2]),
ht ((1/m2) GravForce[m1, {0, 0}, m2,
x + k2/2]),
h ((1/m2) GravForce[m1, {0, 0}, m2,
x + k3]),
h v,
h (v + k1 /2),
h (v + k2/2),
h (v + k3),
v + (1/6) (k1 + 2 k2 + 2 k3 + k4),
x + (1/6) (vk1 + 2 vk2 + 2 vk3 + vk4)
}
But I'm fairly sure that this is entirely wrong despite the fact that it gives me a "correct" result - for one thing, it's not significantly more accurate with the same value of h than Euler's Method. The other is that the functions themselves look completely and utterly wrong.
Could someone help me out here? This is really spinning my head around.
I'm not really looking for help with Mathematica, just more of a general guide on how Runge-Kutta is supposed to work for a system like this.
Last edited: