# 4th-order Runge-Kutta method for coupled harmonic oscillator

I’m attempting to write a C program to gather values from a coupled spring system: There is a wall, connected to a mass $m_1$ by a spring, then this mass is connected to a second mass $m_2$ by another spring.

The values I require are the positions of the two masses and their velocities.

Using initial values for position and velocity I intend to calculate the movement of the two masses using the 4th-order Runge–Kutta method. I have successfully done this for positions, but I can’t figure out how to do it for the velocities. The differential equations for the velocities are:

\begin{alignat}{2} \dot v_1 &= -\omega_1^2(x_1-R_1) &+ \omega_2^2(x_2-x_1-w-R_2)\\ \dot v_2 &= &- \omega_2^2(x_2-x_1-w-R_2) \end{alignat}

Where $R$ is the rest length of the springs, $x$ is the position, $w$ is the width. The equations are correct; that isn’t the problem.

The problem I have is that I just don’t know how to express the Runge–Kutta algorithm for the velocities when both $x$ positions are changing, do I increase them both at the same time in the algorithm? Do I increase one and then take the average?

\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)