From the first figure
Taking the two blocks plus the spring as a system:
Since there is an external force F on the system, there will be some acceleration of the center of mass, which can be calculated by the formula:
−−→acm=−−→FextM
Where,
−−→Fext is the net external force on the system
M is the total mass of the system
a = Fm + M
Now, let us solve this problem from the frame of reference of a centre of mass. This means that we would have to apply a pseudo force ma towards left of the block of mass m and another pseudo force Ma towards left on the block of massM .
Net external force on the block of mass m is
F1 = ma = mFm+M
This force will be in the left direction
Net external force on the block of mass M is
F2 = F – Ma
= F – MFm+M=mFm +M
This force will be in the right direction
The situation from the frame of centre of mass would be as shown in the picture below:
From the second figure
The centre of mass is at rest in this frame, the blocks will move in opposite directions and after some time, when the extension of the spring is maximum, they will come to rest for an instant. Let the block of mass m moves a distance x1 and the block of mass M moves a distance x2. The total work done by the forces F1 and F2 will be:
W = F1 x1 + F2 x2
= mFm+M(x1+x2)
This work done should be equal to the change in potential energy of the spring because the change in kinetic energy will be zero from the frame of center of mass
mFm+M(x1+x2)=12k(x1+x2)2
Or
(x1+x2)=2mFk(m+M)
Hence maximum extension in spring is (x1+x2)=2mFk(m+M)