EJSS simple harmonic motion model with energy vs x graph showing elastic potential, kinetic and total energy
based on models and ideas by
http://weelookang.blogspot.sg/2014/02/ejssshmevsx.html EJSS simple harmonic motion model with energy vs t graph showing elastic potential, kinetic and total energy https://dl.dropboxusercontent.com/u/44365627/lookangEJSworkspace/export/ejss_model_SHMet/SHMet_Simulation.html source: https://dl.dropboxusercontent.com/u/44365627/lookangEJSworkspace/export/ejss_src_SHMex.zip author: lookang author of EJSS 5.0 Francisco Esquembre 
 lookang http://weelookang.blogspot.sg/2010/06/ejsopensourcesimpleharmonicmotion.html?q=SHM
 Wolfgang Christian and Francisco Esquembre http://www.opensourcephysics.org/items/detail.cfm?ID=13103
http://weelookang.blogspot.sg/2014/02/ejssshmevsx.html EJSS simple harmonic motion model with energy vs t graph showing elastic potential, kinetic and total energy https://dl.dropboxusercontent.com/u/44365627/lookangEJSworkspace/export/ejss_model_SHMet/SHMet_Simulation.html source: https://dl.dropboxusercontent.com/u/44365627/lookangEJSworkspace/export/ejss_src_SHMex.zip author: lookang author of EJSS 5.0 Francisco Esquembre 
notes:
http://weelookang.blogspot.sg/2014/02/ejssshmevsx.html EJSS simple harmonic motion model with energy vs t graph showing elastic potential, kinetic and total energy https://dl.dropboxusercontent.com/u/44365627/lookangEJSworkspace/export/ejss_model_SHMet/SHMet_Simulation.html source: https://dl.dropboxusercontent.com/u/44365627/lookangEJSworkspace/export/ejss_src_SHMex.zip author: lookang author of EJSS 5.0 Francisco Esquembre 
The equations that model the motion of the spring mass system are:
$ F =  k x $
where $ F $ is the restoring elastic force exerted by the spring (in SI units: N), k is the spring constant (N·m−1), and x is the displacement from the equilibrium position (in m).
where the terms
$ \frac{k}{m}(xl) $ represents the restoring force component as a result of the spring extending and compressing.
$  \frac{bv_{x}}{m}$ represents the damping force component as a result of drag retarding the mass's motion.
$ + \frac{A sin(2 \pi f t)}{m} $ represents the driving force component as a result of a external periodic force acting the mass $ m $.
Once the mass is displaced from its equilibrium position, it experiences a net restoring force. As a result, it accelerates and starts going back to the equilibrium position. When the mass moves closer to the equilibrium position, the restoring force decreases. At the equilibrium position, the net restoring force vanishes. However, at x = 0, the mass has momentum because of the impulse that the restoring force has imparted. Therefore, the mass continues past the equilibrium position, compressing the spring. A net restoring force then tends to slow it down, until its velocity reaches zero, whereby it will attempt to reach equilibrium position again.
As long as the system has no energy loss, the mass will continue to oscillate. Thus, simple harmonic motion is a type of periodic motion.
At the time of release, the energy of the system will consist totally of the spring’s potential energy. As the spring pulls the mass toward the equilibrium position, the potential energy is transformed into kinetic energy until at the equilibrium position the kinetic energy will reach a maximum. After the mass crosses the equilibrium position, the spring is compressed and the EP is converted to EK. Maximum PE occurs at maximum compression of spring.
The constant exchange between potential energy EP and kinetic energy EK is essential in producing oscillations. The total energy ET, which is the summation of kinetic and potential energy, will always add up to a constant value as shown.
Variation with time of energy in simple harmonic motion are as follows:
$ KE = \frac{1}{2}mv^{2} = \frac{1}{2} m \omega^{2} x_{o}^{2} cos^{2} ( \omega t ) $
$ PE = \frac{1}{2}kx^{2} = \frac{1}{2} m \omega^{2} x_{o}^{2} sin^{2} ( \omega t ) $
$ TE = KE + PE = \frac{1}{2} m \omega^{2} x_{o}^{2} $
therefore , in general:
Thus, this model assumes
$ \frac{\delta x}{\delta t} = v_{x} $
$ \frac{\delta v_{x}}{\delta t} = \frac{k}{m}(xl)  \frac{bv_{x}}{m} + \frac{A sin(2 \pi f t)}{m} $
where the terms
$ \frac{k}{m}(xl) $ represents the restoring force component as a result of the spring extending and compressing.
$  \frac{bv_{x}}{m}$ represents the damping force component as a result of drag retarding the mass's motion.
$ + \frac{A sin(2 \pi f t)}{m} $ represents the driving force component as a result of a external periodic force acting the mass $ m $.
What is SHM?
Simple harmonic motion is typified by the motion of a mass on a spring when it is subject to the linear elastic restoring force given by Hooke's Law. The motion is sinusoidal in time and demonstrates a single resonant frequency. In order for simple harmonic motion to take place, the net force of the object at the end of the pendulum must be proportional to the displacement. In other words, oscillations are periodic variations in the value of a physical quantity about a central or equilibrium value.As long as the system has no energy loss, the mass will continue to oscillate. Thus, simple harmonic motion is a type of periodic motion.
Energy of SHM:
Consider a spring of spring constant k connected to a mass m as shown. When the mass is displaced from its equilibrium position by a distance xo and released, it will oscillate backwards and forwards
At the time of release, the energy of the system will consist totally of the spring’s potential energy. As the spring pulls the mass toward the equilibrium position, the potential energy is transformed into kinetic energy until at the equilibrium position the kinetic energy will reach a maximum. After the mass crosses the equilibrium position, the spring is compressed and the EP is converted to EK. Maximum PE occurs at maximum compression of spring.
The constant exchange between potential energy EP and kinetic energy EK is essential in producing oscillations. The total energy ET, which is the summation of kinetic and potential energy, will always add up to a constant value as shown.
Variation with time of energy in simple harmonic motion are as follows:
If motion starts at the equilibrium position and starts to move to the positive direction solutions to the defining equation are:
$ x = x_{o} sin ( \omega t ) $
motion starts at the equilibrium position and starts to move to the positive direction, defining equation follows $ x = x_{o} sin ( \omega t ) $ 
$ v = x_{o} \omega cos ( \omega t ) $
motion starts at the equilibrium position and starts to move to the positive direction, defining equation follows $ v = x_{o} \omega cos ( \omega t ) $ 
$ a =  x_{o} \omega^{2} sin ( \omega t ) $
$ KE = \frac{1}{2}mv^{2} = \frac{1}{2} m \omega^{2} x_{o}^{2} cos^{2} ( \omega t ) $
$ PE = \frac{1}{2}kx^{2} = \frac{1}{2} m \omega^{2} x_{o}^{2} sin^{2} ( \omega t ) $
$ TE = KE + PE = \frac{1}{2} m \omega^{2} x_{o}^{2} $
$ KE = \frac{1}{2}mv^{2} = \frac{1}{2} m \omega^{2} ( x_{o}^{2} x^{2}) $
$ PE = \frac{1}{2}kx^{2} = \frac{1}{2} m \omega^{2} x^{2} $
$ TE = KE + PE = \frac{1}{2} m \omega^{2} x_{o}^{2} $
$ KE = \frac{1}{2}mv^{2} = \frac{1}{2} m \omega^{2} ( x_{o}^{2} x^{2}) $
$ PE = \frac{1}{2}kx^{2} = \frac{1}{2} m \omega^{2} x^{2} $
$ TE = KE + PE = \frac{1}{2} m \omega^{2} x_{o}^{2} $

If the motion starts to the negative amplitude position:
$ x =  x_{o} cos ( \omega t ) = x_{o} sin ( \omega t  \frac{\pi }{2} )$
motion starts at the negative position and starts to move to the positive direction, defining equation follows $ x =  x_{o} cos ( \omega t ) = x_{o} sin ( \omega t  \frac{\pi }{2} )$ 
$ v = x_{o} \omega sin ( \omega t ) = x_{o} \omega cos ( \omega t  \frac{\pi }{2} )$
motion starts at the negative position and starts to move to the positive direction, defining equation follows $ v = x_{o} \omega sin ( \omega t ) = x_{o} \omega cos ( \omega t  \frac{\pi }{2} )$ 
$ a = x_{o} \omega^{2} cos ( \omega t ) =  x_{o} \omega^{2} sin ( \omega t  \frac{\pi }{2} )$
$ KE = \frac{1}{2}mv^{2} = \frac{1}{2} m \omega^{2} x_{o}^{2} sin^{2} ( \omega t ) $
$ PE = \frac{1}{2}kx^{2} = \frac{1}{2} m \omega^{2} x_{o}^{2} cos^{2} ( \omega t ) $
$ TE = KE + PE = \frac{1}{2} m \omega^{2} x_{o}^{2} $
therefore , in general:
$ x = x_{o} sin ( \omega t  \phi ) $
$ v = x_{o} \omega cos ( \omega t  \phi ) $
$ a =  x_{o} \omega^{2} sin ( \omega t  \phi ) $
$ KE = \frac{1}{2}mv^{2} = \frac{1}{2} m \omega^{2} x_{o}^{2} cos^{2} ( \omega t  \phi) $
$ PE = \frac{1}{2}kx^{2} = \frac{1}{2} m \omega^{2} x_{o}^{2} sin^{2} ( \omega t  \phi) $
$ TE = KE + PE = \frac{1}{2} m \omega^{2} x_{o}^{2} $
$ KE = \frac{1}{2}mv^{2} = \frac{1}{2} m \omega^{2} x_{o}^{2} cos^{2} ( \omega t  \phi) $
$ PE = \frac{1}{2}kx^{2} = \frac{1}{2} m \omega^{2} x_{o}^{2} sin^{2} ( \omega t  \phi) $
$ TE = KE + PE = \frac{1}{2} m \omega^{2} x_{o}^{2} $
$ KE = \frac{1}{2}mv^{2} = \frac{1}{2} m \omega^{2} ( x_{o}^{2} x^{2}) $
$ PE = \frac{1}{2}kx^{2} = \frac{1}{2} m \omega^{2} x^{2} $
$ TE = KE + PE = \frac{1}{2} m \omega^{2} x_{o}^{2} $