I am trying to solve a set of two 2nd order ODE using the 4th order Runge-Kutta method. The original equations are of the following form: $$\frac{d^2r}{dt^2}=f(r,\theta)$$ $$\frac{d^2\theta}{dt^2}=g(r,\theta)$$
Then, I expressed the above two 2nd order ODEs as four 1st order ODEs as follows: $$\frac{dr}{dt}=R \qquad\\ \frac{dR}{dt}=f(r,\theta)\\ \frac{d\theta}{dt}=\Theta \qquad\\ \frac{d\Theta}{dt}=g(r,\theta)$$
Now, I require to solve these four equations simultaneously using the 4th order Runge-Kutta method. According to the RK4 algorithm, I wrote the equations for a single iteration as follows:
$$k_1=hR_i \\ l_1=hf(r_i,\theta_i) \\ m_1=h\Theta_i \\ n_1=hg(r_i,\theta_i) \\ k_2=h(R_i+l_1/2) \\ l_2=hf(r_i+k_1/2,\theta_i+m_1/2) \\ m_2=h(\Theta_i+n_1/2) \\ n_2=hg(r_i+k_1/2,\theta_i+m_1/2) \\ k_3=h(R_i+l_2/2) \\ l_3=hf(r_i+k_2/2,\theta_i+m_2/2) \\ m_3=h(\Theta_i+n_2/2) \\ n_3=hg(r_i+k_2/2,\theta_i+m_2/2) \\ k_4=h(R_i+l_3) \\ l_4=hf(r_i+k_3,\theta_i+m_3) \\ m_4=h(\Theta_i+n_3) \\ n_4=hg(r_i+k_3,\theta_i+m_3) \\$$
Then the $r$ and $\theta$ variables can be calculated as $$r_{i+1}=r_i+\frac{1}{6}(k_1+2k_2+2k_3+k_4) \\ \theta_{i+1}=\theta_i+\frac{1}{6}(m_1+2m_2+2m_3+m_4)$$
Since there are dependencies in the numerical calculations, I am not sure whether the sequence in which the above equations are correct or not. All the individual equations written above are correct and I am only concerned with the sequence.
Can someone please check the sequence and suggest any changes if anything is incorrect?