Energy in simple harmonic motion

Let us consider the kinetic and potential energy for a spring-mass system. The kinetic energy is
EK=12mv2,

whilst the potential energy for the spring-mass system is

EP=12kx2,

which means that mechanical energy is

EM=EK+EP=12mv2+12kx2.

Is the potential energy formula EP=12kx2 true for all kinds of simple harmonic motion?

The definition of simple harmonic motion is that

ax.

Since F=ma according to Newton's second law, the net force must also be proportional to the position:

F=cx,

where c is a constant for a given system.

The potential energy is:

EP(x)=Wx0=x0xF(x)dx=x0x(cx)dx=c[x22]x0x=12cx212cx20.

If the reference position is in the origin, the general formula of the potential energy is identical in form to the potential energy of the spring-mass system:

EP(x)=12cx2.

The table below shows the values of the different forms of energy in certain positions of the system. We can see that the law of conservation of mechanical energy is fulfilled as the mechanical energy is the same in all these positions.

The mechanical energy is

EM=EK+EP=12mv2+12kx2,

EM=12mA2ω2cos2(ωt+ϕ0)+12kA2sin2(ωt+ϕ0).
There exists a relationship between k and ω:

ω2=km  mω2=k.

Thus the mechanical energy is a constant value during the motion:

EM=12kA2cos2(ωt+ϕ0)+12kA2sin2(ωt+ϕ0),

EM=12kA2[cos2(ωt+ϕ0)+sin2(ωt+ϕ0)]=12kA2.