Due to one dimensional elastic collision of identical bodies, velocity is transferred totally to m1.
Let x1 and x2 be positions of m1 and m2 at a time t. Then extension in the spring (with natural length = l)
x = x2 – x1 – l ...(1)
The equation of motion of m1 is writen as
From these
Solving these,
From(i) and (ii)