By combining Newton's second law with Hooke's law and noting that the acceleration is just , we obtain
.
The solution of this differential equation for can be expressed as
,
where is is the amplitude of the oscillation, i.e. its maximum displacement, and is the initial phase. In the animations below, we have set and thus