Let a light spring of unstretched length l_{o} having spring constant K , is fixed at one end on the vertical wall and kept horizontally.
The free end is pulled to stretch the spring by x , slowly. The force in the spring developed due to elongation in the spring is given by

$\displaystyle \vec{F} = -K\vec{x} $

where x is the displacement of the free end of the spring. Since this magnitude of the force s is proportional to the magnitude of elongation, the force is a variable force. Thus the work done by the spring force for further elementary displacement dx is given by

$ \displaystyle dW = \vec{F}.\vec{dx} $ …(i)

It is assumed that $|\vec{F}|$ does not change significantly for further elementary displacement $|\vec{dx}|$

Therefore, the net work done for the entire outward elongation ‘ x ‘ is

$ \displaystyle W = \int_{0}^{x}\vec{F}.\vec{dx}$

$\displaystyle W = \int_{0}^{x}-K\vec{x}.\vec{dx}$ ….(ii)

The negative sign indicates that F is opposite to x . But x and dx are along the same direction.

i.e. Cosθ = Cos0° = 1

Therefore, $ \displaystyle W = -K\int_{0}^{x}x dx $

$\displaystyle W = -\frac{1}{2}K x^2 $ ……..(iii)

Similarly the work done by the applied force in stretching the spring is

$ \displaystyle W = \int_{0}^{x}\vec{F}.\vec{dx}$

As it is mentioned earlier that the free end of the spring is pulled with uniform velocity, therefore

|F^{→} | = |F_{i}^{→}| = Kx

$ \displaystyle W = \frac{1}{2}K x^2 $

This is the work done by the applied force.

Exercise : Find the work done by an external agent in lowering a block of mass m slowly on a light spring of stiffness k , till it comes to rest.