At the point of maximum displacement (a), the elastic potential energy of the spring is maximum:
while the kinetic energy is zero, because at the maximum displacement the mass is stationary, so its velocity is zero:
And the total energy of the system is
Viceversa, when the mass reaches the equilibrium position, the elastic potential energy is zero because the displacement x is zero:
while the mass is moving at speed v, and therefore the kinetic energy is
And the total energy is
For the law of conservation of energy, the total energy must be conserved, therefore
. So we can write
that we can solve to find an expression for v: