User:Dgies/RK4

I'm trying to get a better feel for how Runge-Kutta methods work and I'm a little confused on how you perform a double integration in the case where in $$\quad y'' = f(t, y'), f(t,y')$$ is co-dependant a family of other $$\quad y(t)$$ equations. The specific situation I'm trying to solve is where $$\quad y(t)$$ describes the position of a particle and $$\quad y''$$ describes the acceleration, which is defined as a function of $$\quad y(t)$$ and the positions of a number of other particles governed by the same similar equations, let's call their positions $$\quad Y_1(t), Y_2(t), ... , Y_n(t)$$ Now imagine you want to compute $$\quad y(t_0 + h)$$ well then you must find $$\quad y'(t,y), y'(t+h/2,y)$$

Generic RK4 method

 * $$ y' = f(t, y), \quad y(t_0) = y_0 $$

Then, the RK4 method for this problem is given by the following equation:


 * $$ y_{n+1} = y_n + {h \over 6} (k_1 + 2k_2 + 2k_3 + k_4) $$

where


 * $$ k_1 = f \left( t_n, y_n \right) $$


 * $$ k_2 = f \left( t_n + {h \over 2}, y_n + {h \over 2} k_1 \right) $$


 * $$ k_3 = f \left( t_n + {h \over 2}, y_n + {h \over 2} k_2 \right) $$


 * $$ k_4 = f \left( t_n + h, y_n + hk_3 \right) $$

---

RK4 double integral for gravity

 * $$\quad dv / dp$$ be the variation of velocity with position due to gravitational potential

Calculating position from velocity

 * $$ p(t_0 + h) = p(t_0) + {h \over 6} (v_A + 2v_B + 2v_C + v_D) $$


 * $$ v_A = v \left( t_0, p(t_0) \right) $$


 * $$ v_B = v \left( t_0 + {h \over 2}, p(t_0) + {h \over 2} v_A \right) $$


 * $$ v_C = v \left( t_0 + {h \over 2}, p(t_0) + {h \over 2} v_B \right) $$


 * $$ v_D = v \left( t_0 + h, p(t_0) + h v_C \right) $$

Calculate velocity from acceleration

 * $$v(t_0+h, p_0 + dp) = v(t_0, p_0) + dp{dv \over dp} + {h \over 6} (a_A + 2a_B + 2a_C + a_D)$$


 * $$ a_A = a \left( t_0, v(t_0) \right) $$


 * $$ a_B = a \left( t_0 + {h \over 2}, v(t_0) + {h \over 2} a_A \right) $$


 * $$ a_C = a \left( t_0 + {h \over 2}, v(t_0) + {h \over 2} a_B \right) $$


 * $$ a_D = a \left( t_0 + h, p(t_0) + h a_C \right) $$


 * $$a(t_0+h, v_0 + dv) = a(t_0, v_0) + dv{da \over dv} + {h \over 6} ((da/dt)_A + 2(da/dt)_B + 2(da/dt)_C + (da/dt)_D)$$