# Two masses attached to a spring

Given a spring with spring constant $k$ whose extension is in the direction $x$, the magnitude of the force that the spring exerts is given by $$|\vec{F}| = F = k|L-l|$$ where $L$ is its length and $l$ is its equilibrium length. Now, imagine that the two masses are at positions $x_1$ and $x_2$ with $x_2>x_1$, then the length of the spring is given by $L = x_2 - x_1$ so that the magnitude of the force exerted by the spring is given by $$|\vec{F}| = F = k|(x_2-x_1) - l|$$ Now, if $x_2 - x_1>l$, then the spring is stretched in which case the mass on the right feels a force of this magnitude to the left, and the mass on the left feels a force of the same mangitude to the right; \begin{align} F_1 = k(x_2-x_1 - l) \\ F_2 = -k(x_2 - x_1 - l) \end{align} This results in the following two equations of motion \begin{align} m\ddot x_1 = -k(x_1-x_2 + l) \\ m \ddot x_2 = -k(x_2 - x_1 - l) \end{align} Essentially, the difference in the sign of $l$ can be attributed to Newton's third law; the forces on each mass must be equal and magnitude, but opposite in direction.

If friction were included on the surface, say for the sake of concreteness that the coefficient of kinetic friction is $\mu_k$, then each object experiences a force equal in magnitude to $\mu_k m_1g$ for mass 1 and $\mu_k m_2 g$ for mass $2$. The sign of the friction force term must be chosen so as to always give a friction force that is opposite the direction of motion. One way to do this is to multiply the force's magntiude by $-\dot x/|\dot x|$ which is $-1$ when the object is moving to the right, and $+1$ when the object is moving to the left.

Thus, with friction the equations of motion can be written as \begin{align} m\ddot x_1 = -k(x_1-x_2 + l) - \mu_k m_1g\frac{\dot x_1}{|\dot x_1|} \\ m \ddot x_2 = -k(x_2 - x_1 - l) - \mu_k m_2g\frac{\dot x_2}{|\dot x_2|} \end{align} As you can tell, these differential equations are considerably harder to solve in general.