# Ordinary Differential Equations/Simple Harmonic Motion

Simple Harmonic Motion can be used to describe the motion of a mass at the end of a linear spring without a damping force or any other outside forces acting on the mass. It's best thought of as the motion of a vibrating spring.

## Laws of Motion

There are generally two laws that help describe the motion of a mass at the end of the spring.
* Hooke's Law
* Newton's Second Law

### Hooke’s Law

To demonstrate Hooke’s Law, we will use a (massless) spring hung from a ceiling. The ceiling is rigid, and offers no effect on the spring’s motion.
If we leave the spring alone, and don’t attach a mass, the spring will remain in an un-stretched state with a total length $l$. Now, if we attach an arbitrary mass ($m_{1}>0$) to the free end of the spring, then the spring will stretch a distance ($s$) from the original length ($l$). So now ${\mbox{length}}_{\mbox{total}}=s+l$.
Eventually, the mass will come to rest at this new total length at a position known as the Equilibrium Position. This position is what many of the calculation reference as $x=0$.
Here is where Hooke's law comes into play. As the spring stretches, when the mass is attached, a force is exerted on the mass in the direction of the original un-stretched position. This force is expressed using the equation: ${\vec {F}}={\vec {k}}s$. Where ${\vec {F}}$ is the force exerted on the mass by the spring, ${\vec {k}}$ is the spring's Constant of Proportionality, often called the spring constant, and $s$ is the distance the spring stretched from its un-stretched position.
Suppose that any movement by the mass in a downward direction is considered positive and upward is negative. If you take the weight (${\vec {W}}$) of the mass, it will be equal to the force exerted by the spring when $x=0$, or the equilibrium position. Due to this, we now know that ${\vec {W}}={\vec {F}}$. Since ${\vec {W}}=m{\vec {g}}$ and ${\vec {F}}={\vec {k}}s$, by substitution, we get $m{\vec {g}}={\vec {k}}s$. If you set these equal to zero, you'll get $m{\vec {g}}-{\vec {k}}s=0$.
Why is ${\vec {k}}s$ negative? This is because no matter what the mass does, the spring-with-gravity combination will always exert a force opposite to its motion. For example, as the mass travels downward beyond the equilibrium point, the spring will pull it back upwards in an attempt to regain equilibrium. When the mass gets above the equilibrium point, the spring contribution is less and the net acceleration is then downward toward regaining equilibrium. It behaves the same as if in an idealized example imagined all far removed from any local gravity effect, and that the spring is alternately stretched and compressed about a completely unstressed state. Some examples invent a horizontal version with the mass sliding over a frictionless surface, the better to then introduce a friction component.

#### Examples
##### Example 1

A mass of $1/4{\mbox{ slug}}$ is attached to a spring and stretches it $6{\mbox{ inches}}$. Calculate the spring's constant of proportionality.
Solution Using the combined equation $mg-ks=0$, we know $m=1/4{\mbox{ slug}}$ and $s=6{\mbox{ inches}}=1/2{\mbox{ ft}}$
(we omit the vector since we're only looking for a magnitude)
By definition, we know $g=32ft/s^{2}$
Plugging everything in, we get $(1/4slug)(32ft/s^{2})-k(1/2ft)=0$.
Solving for $k$, we find $8{\mbox{ lb}}=k(1/2{\mbox{ ft}})$ $16{\mbox{ lb}}/{\mbox{ft}}=k$

##### Example 2

An object of unknown mass stretches a spring 10 cm from the ceiling. The spring's original length was 7 cm. Calculate the weight of the object if the spring constant is 5 N/m.
Solution First, we need the distance the spring is stretched after the mass is attached. This can be found using ${\mbox{length}}_{\mbox{total}}=s+l$, where ${\mbox{length}}_{\mbox{total}}=10{\mbox{ cm}}=.1{\mbox{ m}}$ and $l=7{\mbox{ cm}}=.07{\mbox{ m}}$. Plugging everything in and solving for $s$ we find $s=.03{\mbox{ m}}$.
By definition we know $W=mg$. With that, and $mg-ks=0$, we plug everything in and solve for $W$.
$W-(5{\mbox{ N}}/{\mbox{m}})(.03{\mbox{ m}})=0$ $W=.15{\mbox{ N}}=150{\mbox{ g}}$

### Newton’s Second Law of Motion

Now, imagine that we have another mass hanging from a spring, which is attached to the ceiling. This mass is then pulled down a distance $x$, below the equilibrium point, and released. By Hooke's Law, the spring will be pulled back up, and after reaching it's highest point, start to travel back down.
If the mass continues this motion, without any outside influence, it's known as Free Motion. During this motion, there is acceleration acting on the mass to keep it in motion. This acceleration can be readily found in Newton's Second Law of Motion using ${\vec {F}}=m{\vec {a}}$. Where ${\vec {F}}$ is the force of the spring acting on the mass $m$ and ${\vec {a}}$ is the acceleration of that mass due to the force acting on it.
From Calculus, we know that $a={\frac {d^{2}x}{dt^{2}}}$ or $a={\ddot {x}}$. If we substitute this into our equation from the section on Hooke's Law, we find $m{\ddot {x}}-k(s+x)=0$. However, since this motion is always in the direction of the spring's force, our equation becomes $m{\ddot {x}}+k(s+x)=mg$. Expanding this, and solving for $m{\ddot {x}}$ we get $m{\ddot {x}}=-k(s+x)+mg=-ks-kx+mg$. Knowing that $mg-ks=0$, we can simplify our equation to end with $m{\ddot {x}}=-kx$.

## The Differential Equation of Free Motion or SHM

Finally, if we set the equation above equal to zero, we end up with the following:
$m{\ddot {x}}+kx=0$
Since our leading coeffiecient should be equal to 1, we divide by the mass to get:
${\ddot {x}}+{\frac {k}{m}}x=0$
If we set $\omega ^{2}={\frac {k}{m}}$, we'll have our final form of this equation:
${\ddot {x}}+\omega ^{2}x=0$
The above equation is known to describe Simple Harmonic Motion or Free Motion.

### Initial Conditions

With the free motion equation, there are generally two bits of information one must have to appropriately describe the mass's motion.
* The starting position of the mass. $x_{2}$
* The starting direction and magnitude of motion. $v$
Generally, one isn't present without the other. For simplicity, we will consider all displacement below the equilibrium point as $x>0$ and above as $x<0$.
For upward motion $v<0$, and for downward motion $v>0$.

### Solution

Multiplying this equation by ${\dot {x}}$ gives:
$m{\ddot {x}}{\dot {x}}+kx{\dot {x}}=0$
The first and the second addends are exact derivatives, so this equation may be integrated to obtain the following relation:
$m{\frac {{\dot {x}}^{2}}{2}}+k{\frac {x^{2}}{2}}=E$
The first addend of this relation is known as the kinetic energy of the mass and the second — as the potential energy of the spring. The above integral represents the energy conservation law. This is also a first order separable differential equation. It may be rewritten as
${\frac {dx}{\sqrt {{\frac {2E}{m}}-{\frac {k}{m}}x^{2}}}}=\pm dt$
The integration of this relation gives
$\arccos x{\sqrt {\frac {k}{2E}}}=\pm {\sqrt {\frac {k}{m}}}t+\varphi$
Or, finally rearranging the result, substituting $\omega ={\sqrt {k/m}}$, and solving for $x$ we obtain
$x={\sqrt {\frac {2E}{k}}}\cos(\omega t+\varphi )$