I have the same problem as in this question.
But can someone elaborate on the answer? The poster says that:
Solving this system of 4 ODE's with rk4 will solve for all your state variables simultaneously. position and velocity do not need to be handled seperately (and shouldn't be).
How is this actually implemented? There is still no expression that I can see for $v$, so I do not see how we can obtain the RK coefficients, and I cannot see how to handle position and velocity ‘not seperately’.
For a system of 2 coupled oscillators we have:
$m_1\ddot{x}_1=-k_1x_1+k_2(-x_1+x_2)$
$m_2\ddot{x}_2=-k_3x_2+k_2(x_1-x_2)$
where $x_1$ and $x_2$ are the displacements of masses 1 and 2 from their equilibrium positions. If we then substitute $v=\dot{x}$, we get:
$\dot{v}_1m_1=-k_1x_1+k_2(-x_1+x_2)$
and similar for $\dot{v}_2$. The answer to the question I linked suggested we combine the system to give (they have used a slightly different functional form but the underlying mechanics is the same):
$$ \left(\begin{array}{c} \dot{x}_1 \\ \dot{x}_2 \\ \dot{v}_1 \\ \dot{v}_2 \end{array}\right) = \left(\begin{alignat}{1} & v_1 \\ & v_2 \\ -\omega_1^2(x_1-R_1) &+ \omega_2^2(x_2-x_1-w-R_2)\\ &-\omega_2^2(x_2-x_1-w-R_2) \end{alignat}\right) $$
However I'm unsure how to actually proceed from here. RK4 algorithm needs to evaluate the RK coefficients at different timesteps, and my issue is $\dot{v}=f(x_1,x_2)$ instead of $\dot{v}=f(v)$ in normal (uncoupled) RK4. I can't find $v$ at a new timestep as I need $x$ to do that, and I can't find $x$ without $v$. Is it a matter of writing some operator matrix equation and solving that?