# Simple Harmonic Oscillator

If someone asked me: "Is there a concept in physics that appears over and over again during the studies? Something that is undoubtedly worth spending some time on initially in order to gain a profound understanding from the very beginning?" Well, the first thing that would definitely come to my mind is the concept of the harmonic oscillator. The harmonic oscillator is the simplest model of a physical oscillation process and it is applicable in so many different branches of physics - oscillations are just everywhere!

## Assumptions

An intuitive example of an oscillation process is a mass which is attached to a spring (see fig. 1). There is an equilibrium position of the mass for which its total potential energy has a minimum. This implies that any displacement of the mass from this equilibrium causes a restoring force that tends to push the mass back into its equlibrium position. A simple harmonic oscillator is an idealised system in which the restoring force is directly proportional to the displacement from equlibrium (which makes it *harmonic*) and where there is neither friction nor external driving (which makes it *simple*).

## Equation of Motion

The equation of motion is given by Newton's second law which relates the particle acceleration $\ddot{x}(t)$ to the restoring force $-k\, x(t)$ (given by Hooke's law) with $k$ being the spring constant:^{[1]}^{[2]}
\begin{align}
&m \,\ddot{x}(t) = - k \,x(t) \nonumber\\
\Leftrightarrow \quad &m \,\ddot{x}(t) + k\, x(t) = 0 \label{eq:equation-of-motion}
\end{align}

This is a differential equation with the following properties:^{[3]}

- It is
**ordinary**: There is only one indipendent variable, $t$. **linear**: If $x_1(t)$ and $x_2(t)$ are solutions and $a$ and $b$ some coefficients, then $a\,x_1(t)+ b\,x_2(t)$ is a solution as well.**homogeneous**: All occuring terms are multiples of x(t) or one of its derivatives.- and
**second-order**: The highest occuring derivative is of order 2.

If you are rather new to solving differential equations: There are no hard or fast general rules, how to find a solution for a specific case and you cannot even be certain that there is a solution at all. Therefore, solving differential equations requires some experience, a thorough study of the equations' properties and also a good intuition. Fortunately, the one we are studying now is one of the straightforward cases!

## Solution

According to the existence and uniqueness theorem, for this differential equation there exists a unique solution for every pair of initial conditions.^{[4]} The initial conditions are the position $x_0 := x(t_0)$ and the velocity $v_0 := \dot{x}(t_0)$ of the mass $m$ at some initial time $t_0$. For convenience one can set $t_0=0$ in order to simplify the later equations (without loss of generality). Now the objective is to find a function that solves eq. \eqref{eq:equation-of-motion} for *all* possible initial conditions. Such a function is referred to as a *general solution*.

### Guessing a Solution

In the equation of motion \eqref{eq:equation-of-motion} $\ddot{x}(t)$ is a multiple of $x(t)$. That implies, that the desired function remains unchanged *up to a constant factor* when taking two derivatives. Do you know any function, for which the second derivative is just a multiple of the function itself? There are in fact various possible candidates, e.g.:
\begin{align}
x(t) = \begin{cases}
\sin(\omega_0 t) \\
\cos(\omega_0 t) \\
\exp(\lambda t)
\end{cases} \qquad \Rightarrow \qquad
\ddot{x}(t) = \begin{cases}
-\omega_0^2 \sin(\omega_0 t) \\
-\omega_0^2 \cos(\omega_0 t) \\
\lambda^2 \exp(\lambda t)
\end{cases}
\end{align}
Here $\omega_0$ and $\lambda$ are just some constants which appear as the factors of proportionality in the functions' derivatives.

#### The Trigonometric Functions

Let us first pick the sine function and verify that it is a valid solution of the equation of motion by inserting it in eq. \eqref{eq:equation-of-motion}: \begin{align} \left[ - m \,\omega_0^2 + k \,\right] \sin (\omega_0 t) = 0 \end{align} This equation is true for all $t$ if and only if the term in square brackets vanishes which is the case if $\omega_0^2 := k/m$. The same can be found for the cosine function.

Now we already found some particular solutions for the differential equation (e.g. $x(t)=\sin(\omega_0t)$ and $x(t)=\cos(\omega_0 t)$). However, so far these solutions serve only individual pairs of initial conditions: \begin{align} x(t) = \sin (\omega_0 t) \quad &\Rightarrow \quad \begin{pmatrix} x(0) \\ \dot{x}(0) \end{pmatrix} = \begin{pmatrix} \sin(\omega_0 \cdot 0) \\ \omega_0\cos(\omega_0 \cdot 0) \end{pmatrix} = \begin{pmatrix} 0 \\ \omega_0 \end{pmatrix} \\[2ex] x(t) = \cos (\omega_0 t) \quad &\Rightarrow \quad \begin{pmatrix} x(0) \\ \dot{x}(0) \end{pmatrix} = \begin{pmatrix} \cos(\omega_0 \cdot 0) \\ -\omega_0\sin(\omega_0 \cdot 0) \end{pmatrix} = \begin{pmatrix} 1 \\ 0 \end{pmatrix} \end{align}

According to the general theory of linear differential equations, the set of solutions of this second-order ODE forms a two-dimensional vector space. The general solution can therefore be obtained by a linear combination of two linearly independent particular solutions. As the two trigonometric functions are linearly independent to each other, one can write:
\begin{align}
x(t) = a \, \sin(\omega_0 t) + b \, \cos(\omega_0 t) \quad \text{with}\quad \omega_0 = \sqrt{\frac{k}{m}} \label{eq:general-solution-sin}
\end{align}
Here $a,b \in \mathbb{R}$ are arbitrary coefficients that can be adjusted to reproduce any set of initial conditions:^{[5]}
\begin{align}
a := \frac{v_0}{\omega_0} \quad\text{and}\quad b:=x_0
\end{align}

The general solution of the simple harmonic oscillator depends on the initial conditions $x_0 = x(t=0)$ and $v_0 = \dot{x}(t=0)$ of the oscillating object as well as its mass $m$ and the spring constant $k$. It is given by: \begin{align} x(t) = \frac{v_0}{\omega_0} \, \sin(\omega_0 t) + x_o \, \cos(\omega_0 t) \quad \text{with}\quad \omega_0 = \sqrt{\frac{k}{m}} \end{align}

#### The Exponential Function

As was noticed above, not only the sine and cosine functions are proportional to their second derivatives but the same also holds for the exponential function and therefore one can construct a general solution from the exponential function as well.
Again, one starts by inserting the ansatz $x(t)=e^{\lambda \,t}$ into the equation of motion \eqref{eq:equation-of-motion} in order to verify that it is a solution:
\begin{align}
\left( m\,\lambda^2 + k \,\right)\,e^{\omega_0 t} &= 0 \nonumber\\
\Rightarrow \lambda = \pm \sqrt{-\frac{k}{m}} &= \pm i \,\omega_0 t
\end{align}
This yields two possible (complex) values for the free parameter $\lambda$ which depend on the specific properties of set-up (spring constant $k$ and mass $m$). Again, one forms the general solution by a linear combination of the corresponding particular solutions $e^{i\omega_0 t}$ and $e^{-i\omega_0 t}$ (which are linearly independent to each other).
\begin{align}
x(t) &= a \, e^{i\omega_0 t} + b \, e^{-i\omega_0 t} \nonumber\\
&= a \left[ \cos(\omega_0 t) + i \sin(\omega_0 t) \right] +
b \left[ \cos(\omega_0 t) - i \sin(\omega_0 t) \right]\nonumber\\
&= \left( a+b \right) \cos(\omega_0 t) + i \left( a-b \right) \sin(\omega_0 t) \label{eq:general-solution-exp}
\end{align}
Here the Euler identity was used in order to rewrite the complex exponential in terms of the trigonometric functions.
Now x(t) is supposed to be a real number as it describes the (real) particle displacement. That is only guaranteed if $a$ and $b$ are complex numbers with $\Im{a+b}=0$ and $\Re{a-b}=0$ such that both terms in eq. \eqref{eq:general-solution-exp} have real pre-factors. This implies that $a$ and $b$ are complex conjugate to each other:
\begin{align}
\Im{a+b} = 0 \quad &\Leftrightarrow \quad \Im{a} = -\Im{b} \nonumber\\
\Re{a-b} = 0 \quad &\Leftrightarrow \quad \Re{a} = \Re{b} \nonumber\\
\Leftrightarrow \quad b &= a^* \label{eq:b-complex-conjugated}
\end{align}
So there is actually only one complex parameter $a$ left with two independent real components $\Re{a}$ and $\Im{a}$ which can again be specified by the initial conditions. Therefore one inserts \eqref{eq:b-complex-conjugated} into \eqref{eq:general-solution-exp} and evaluates x(t) and its derivative at $t=0$:
\begin{align}
\begin{pmatrix}
x(t=0) \\ \dot{x}(t=0)
\end{pmatrix} &\stackrel{\eqref{eq:general-solution-exp}}{=}
\begin{pmatrix}
a+a^* \\ i(a-a^*)\,\omega_0
\end{pmatrix} =
\begin{pmatrix}
x_0 \\ v_0
\end{pmatrix}
\end{align}
Since $\Re{a} = \frac{a+a^*}{2} = \frac{x_0}{2}$ and $\Im{a} = \frac{a-a*}{2i} = -\frac{v_0}{\omega_0}$^{[6]}, one finds:
\begin{align}
\Leftrightarrow \quad a &= \frac{1}{2} \, \left( x_0 - i \frac{v_0}{\omega_0} \right)
\end{align}
The solution becomes - analogously to the result of the previous section:
\begin{align}
x(t) = \frac{v_0}{\omega_0} \, \sin(\omega_0 t) + x_0 \, \cos(\omega_0 t)
\end{align}

### Systematic Approach: Power Series Ansatz

When I was studying differential equations for the first time, I was not really happy with finding a solution by just guessing it. I mean - during all my mathematical education I have learned how to systematically find solutions to mathematical problems by applying general rules. And now I was supposed to just *guess* the solution?

I was wondering if there is a way to actually *derive* that solution. And I am happy to tell you: There is! Well, not in general though, but at least for differential equations which are similar to the one at hand.

The method works as follows: The unknown function $x(t)$ is written as a power series in order to obtain a more concrete representation. By inserting it into the differential equation one can then derive conditions for the coefficients and thereby identify the solution function.

While doing so one tacitly assumes that the desired function can be represented as a power series in the first place. For the sake of compactness, I do not want to discuss the mathematical requirements for that though. However, if one finds a valid solution by this approach, then the method is justified retrospectively.

The power series representation of $x(t)$ is (when being centered at $t=0$) given by^{[7]}
\begin{align}
x(t) = \sum_{n=0}^{\infty} a_n \, t^n \quad \text{with} \quad n\in\mathbb{N} \quad\text{and}\quad a_n \in \mathbb{R} \label{eq:power-series-represantation}
\end{align}
and has the following derivatives:
\begin{align}
\dot{x}(t) &= \sum_{n=1}^{\infty} n\, a_n\, t^{n-1}= \sum_{n=0}^{\infty} (n+1)\, a_{n+1}\, t^n \label{eq:power-series-deriv}\\
\ddot{x}(t) &= \sum_{n=2}^{\infty} n\,(n-1)\, a_n \,t^{n-2} = \sum_{n=0}^{\infty} (n+2)(n+1) \, a_{n+2}\, t^n \label{eq:power-series-sec-deriv}\\
\end{align}
Inserting these expressions into eq. \eqref{eq:equation-of-motion} yields:
\begin{align}
m \,\ddot{x}(t) + k\, x(t) = \sum_{n=0}^{\infty} \left[ m \, (n+2)(n+1)\, a_{n+2} + k\, a_n \right] t^n = 0
\end{align}

This expression is only true if the term in square brackets vanishes.^{[8]} That provides a condition on the choice of the coefficients of the power series:
\begin{align}
m \,(n+2)(n+1)\, a_{n+2} + k \,a_n = 0 \nonumber\\
\Leftrightarrow \quad a_{n+2} = - \frac{k}{m} \frac{a_n}{(n+2)(n+1)} \label{eq:recursion-rule}
\end{align}
The first thing to notice here is that $a_2$ is the coefficient with the lowest index that can actually be computed by the recurrence relation \eqref{eq:recursion-rule}. Therefore, the values for $a_0$ and $a_1$ must be known ab initio in order to obtain a unique solution.

Let us go ahead and find an expression for $a_n$ which is only dependent on the prescribed values $a_0$ and $a_1$ by writing down the first iterations explicitely:
\begin{align}
a_2 &= - \frac{k}{m} \frac{a_0}{2\cdot 1} \\
a_3 &= - \frac{k}{m} \frac{a_1}{3\cdot 2\cdot 1} \\
a_4 &= \left(- \frac{k}{m} \right)^2 \frac{a_0}{4\cdot 3\cdot 2\cdot 1} \\
a_5 &= \left(- \frac{k}{m} \right)^2 \frac{a_1}{5\cdot 4\cdot 3\cdot 2\cdot 1} \\&\qquad\dots \nonumber
\end{align}
In this simple case it is easy to see that the general rule is given by
\begin{align}
a_n =
\begin{cases}
\left( -\frac{k}{m} \right)^{\frac{n}{2}} \frac{a_0}{n} \;\;\qquad n\text{ is even} \\[1ex]
\left( -\frac{k}{m} \right)^{\frac{n-1}{2}} \frac{a_1}{n} \qquad n\text{ is odd}
\end{cases}
\end{align}
and if you are sceptical, you can verify that by induction.^{[9]} And based on the previous sections, from now on the notation $\omega_0 := \frac{k}{m}$ will be used again in order to keep the terms compact.
The expressions for the coefficients $a_n$ can now be used to write down the more specific series representation $x(t)$:^{[10]}
\begin{align}
x(t) &= x_\text{odd}(t) + x_\text{even}(t) \qquad \text{with} \\[2ex]
x_\text{even}(t) :&= \sum_{n\text{ even}} a_0 \left(-\omega_0^2 \right)^{\frac{n}{2}} \frac{t^n}{n!} \qquad \left| \quad j:=\frac{n}{2} \right. \nonumber\\
&= \sum_{j=0}^{\infty} a_0 (-1)^j \omega_0^{2j} \frac{t^{2j}}{(2j)!} \nonumber\\
&= a_0 \sum_{j=0}^{\infty} (-1)^j \frac{\left(\omega_0 t \right)^{2j}}{(2j)!} \nonumber\\
&= a_0 \, \cos(\omega_0 t) \\[2ex]
x_\text{odd}(t) :&= \sum_{n\text{ odd}} a_1 \left(-\omega_0^2 \right)^{\frac{n-1}{2}} \frac{t^n}{n!} \qquad \left| \quad j:=\frac{n-1}{2} \right. \nonumber \\
&= \sum_{j=0}^{\infty} a_1 (-1)^j \omega_0^{2j} \frac{t^{2j+1}}{(2j+1)!} \nonumber \\
&= \frac{a_1}{\omega_0} \sum_{j=0}^{\infty} (-1)^j \frac{\left(\omega_0 t \right)^{2j+1}}{(2j+1)!} \nonumber \\
&= \frac{a_1}{\omega_0} \, \sin(\omega_0 t)
\end{align}
Furthermore, based on eqs. \eqref{eq:power-series-deriv} and \eqref{eq:power-series-represantation} one can easily see that the remaining coefficients are determined by the initial conditions
\begin{align}
x(t=0) = a_0 = x_0 \quad \text{and} \quad \dot{x}(t=0) = a_1 = v_0
\end{align}
such that the solution is given by
\begin{align}
x(t) = x_0 \, \cos(\omega_0 t) + \frac{v_0}{\omega} \, \sin(\omega_0 t)
\end{align}
which reproduces the results of the preceding sections.

In certain cases, the power series approach provides a good way to actually derive solutions of differential equations without making groundless assumptions about the specific form of the solution function. However, even in this rather simple example it involves quite a few steps and is arguably not as elegant as the *guessing approach*. That is why it is usually not the method of choice when teaching how to solve differential equations. And in most cases you will be way faster using for instance the exponential approach straight away as instead of the power series method.

## References

[1] | Grundkurs Theoretische Physik 1 Springer 2012 (ch. 2.3.6) |

[2] | Mathematics for Physics Oxford University Press 2007 (ch. 7.6) |

[3] | Essential Mathematical Methods for Physicists Elsevier Academic Press 2004 (ch. 8.1) |

[4] | Gewöhnliche Differentialgleichungen Spektrum 1992 (ch. 3.2) |

[5] | Grundkurs Theoretische Physik 1 Springer 2012 (ch. 2.3.4) |

[6] | Mathematische Methoden in der Physik Springer Spektrum 2016 (S. 56) |

[7] | Gewöhnliche Differentialgleichungen Spektrum 1992 (ch. 5.2) |

[8] | Gewöhnliche Differentialgleichungen Spektrum 1992 (ch. 5.2) |

[9] | Gewöhnliche Differentialgleichungen Spektrum 1992 (ch. 5.2) |

[10] | Gewöhnliche Differentialgleichungen Spektrum 1992 (ch. 5.2) |