In this problem, we are talking about Mechanical Energy (
) which is the addition of the Kinetic Energy
(energy of the body in motion) and Potential Energy
(It can be Gravitational Potential Energy or Elastic Potential Energy, in this case is the second):
(1)
The Kinetic Energy is:

Where
is the mass of the body and
its velocity
And the Potential Energy (Elastic) is:

Where
is the spring constant and
is the the position of the body.
Knowing this, the equation for the Mechanical Energy in this case is:
(2)
Now, according to the Conservation of the Energy Principle, and knowing there is not friction, the initial energy
must be equal to the final energy
:
(3)
(4)
At the beginning, the block has a
, because it starts from rest, this means the initial energy
is only the Potential Elastic Energy:
(5)
After the spring is compressed, is in its equilibrium point X=0, so
. Then the block is released. This means the final energy
is only the Kinetic Energy
(6)
Now, we have to substitute (5) and (6) in (3):




Finally:
