Solution (source code)

= Solution

Let $x_1,x_2,x_3$ be longitudinal displacements from equilibrium. The original diagram has masses $m,2m,m$, and no attachments to fixed walls. The <Lagrangian> is
$$
L=\tfrac12m(\dot x_1^2+2\dot x_2^2+\dot x_3^2)-\tfrac12k\big[(x_2-x_1)^2+(x_3-x_2)^2\big].
$$
The <Euler-Lagrange equations> give
$$
\boxed{m\ddot x_1=k(x_2-x_1),\quad2m\ddot x_2=k(x_1-2x_2+x_3),\quad m\ddot x_3=k(x_2-x_3).}
$$
The forces sum to zero, consistent with <momentum conservation> for an isolated molecule.