Energy in a spring system

A mass connected to a horizontal spring sits on a frictionless table. The mass is moved to compress the spring, and the system is released from rest. What happens to the energy initially stored in the spring?

The initial energy is Ui = ½ kxi2

The mass accelerates, and when the spring reaches its equilibrium length there is no potential energy left (x=0). At this point all the energy is kinetic - how fast is the mass going?

Apply energy conservation:

Ui + Ki = Uf + Kf

The initial kinetic energy is zero, and the potential energy at the equilibrium point is zero, so:

½ kxi2 = ½ mvf2

vf = xi (k/m)½

The mass keeps going, and the kinetic energy is transformed back into potential energy. This continues, with the total energy remaining constant and the energy going back and forth between potential and kinetic.