A mass on a horizontal spring

Consider a mass on a frictionless horizontal surface. Connect a spring to it and set the system into motion and it will oscillate back and forth. How can we fully describe the motion?

Start with the free-body diagram. The normal force is cancelled by the force of gravity, and the only horizontal force is the spring force. Therefore:

ΣF = ma

-kx = ma

The acceleration is the second derivative of the position with respect to time. This gives:
-kx = m
d2x
dt2
d2x
dt2
= -
k
m
x

Let's guess at a solution: x(t) = A cos(ωt)

Here A represents the amplitude of the oscillation, and ω is called the angular frequency. Also, a sine works just as well as a cosine.

Taking two derivatives of x(t) gives:
v(t) =
dx
dt
= -Aω sin(ωt)
a(t) =
d2x
dt2
=
dv
dt
= -Aω2 cos(ωt)

a = -ω2 x

Compare this to the equation we derived for the mass on the spring:
a = -
k
m
x

This tells us that the angular frequency is given by:
ω2 =
k
m

Motion described by an equation like x(t) = A cos(ωt) is known as simple harmonic motion.

Given that a = -ω2 x, any time you find the acceleration to be proportional to the negative of the displacement you'll have a system experiencing simple harmonic motion, with the angular frequency being the square root of whatever is multiplying -x.