The SHM Equation
To begin the discussion of SHM, we need to understand the equation that describes it.
Table of Contents
Introduction
Suppose we have a mass 
The spring is initially at its natural length 
This means that:
This is a second-order differential equation, known as the equation of motion of a simple harmonic oscillator.
We can alternatively take a Lagrangian approach to derive the same equation.
We know that the spring force is conservative, so we can write its potential energy as 
Plugging this into the Euler-Lagrange equation, we get:
This is the same equation we derived earlier.
It is common to introduce the variable 
The Solution
We can solve this equation multiple ways. I will show three methods here.
First, the fastest way is to take an ansatz of the form:
This is a reasonable guess, as we know that the solution must be periodic. Plugging this into the equation of motion, we get:
This means that 
Additionally, since the same reasoning applies to the sine function, we can also write the solution as a linear combination of sine and cosine:
Secondly, we can enforce energy conservation and derive a solution from there;
We can take 
We can then separate the variables and integrate both sides, which I will not do here (see this for a detailed derivation).
If one is familiar with Hamiltonian mechanics, one might instead consider the phase space of the system 
The eigenvalues of the matrix are 
which means 
where 
Initial Conditions
The solution we derived above is a general solution to the equation of motion. Given that it is a second-order differential equation, we need two initial conditions to fully specify the solution. The two initial conditions can be the initial position and velocity of the mass.
Plugging in the initial conditions, we eventually get a solution of the form:
Parameters of the SHO
Given that we now have a solution to the equation of motion, we can now discuss the parameters of the SHO.
The amplitude is the maximum displacement of the mass from its equilibrium position.
The amplitude is given by 
The period is the time it takes for the mass to complete one full oscillation.
The period is given by 
The frequency is the number of oscillations per unit time.
It is given by 
The angular frequency is the rate of change of the phase of the oscillation.
It is best understood if we consider the solution as the rotation of a complex number.
Then, the angular frequency is just the angle's rate of change.
It is given by 
Linear and Homogeneous Equations
With the introduction of the SHO, we can now discuss the general form of linear and homogeneous equations. The reason that so many physical systems can be modeled as SHOs is that they exhibit common behavior, or at least approximately common behavior. The behavior that we are interested in include the linearity and time-translational invariance of the system.
In a system (with one degree of freedom 
By varying the coefficients 
The function 
or
Suppose we have a solution 
This means that the solution to the equation of motion is the same as if there was no external force acting on the system. In other words, the presence of a gravitational force does not change the oscillation of the mass-spring system. It only "pushes down" the equilibrium position of the mass.
A homogeneous equation is one where the right-hand side (
Suppose we have a solution 
Notice that whenever we have a particular solution to the linear equation, we can always add a solution to the homogeneous equation to get another solution to the linear equation. This means that the general solution to the linear equation is given by the sum of the particular solution and the general solution to the homogeneous equation:
where 
Approximations as SHOs
Many systems can be approximated as SHOs.
To see this, we first write the equation of motion in terms of the potential energy 
We can then Taylor expand the potential energy around the equilibrium position 
For SHOs, the first derivative is also zero because the force is zero and 
In a real system, we have higher-order terms in the Taylor expansion.
With sufficiently small displacements (
For the 
Overall, this means that any 
When a system fails to be approximated as a SHO, this happens because of two reasons.
First, the potential energy might not be analytic around the equilibrium position. Then, we cannot Taylor expand the potential energy.
Second, if 
Time Translation Invariance
The second property of the SHO is that it is time-translationally invariant. Take the homogeneous equation of motion:
and suppose all the coefficients are constant.
Then 
The simplest way 
Solutions of this form are known as irreducible solutions because they behave the simplest under time translations. (More precisely, they are irreducible under the action of the time translation group. A full discussion of this involves representation theory.)
We shall now prove an important theorem:
If a system is linear and time-translationally invariant, then the solution to the equation of motion is a linear combination of irreducible complex exponentials.
We can prove this for a general equation of motion of a complex variable 
First, let's write 
We can borrow language from linear algebra and call the 
Applying time translation to 
Differentiating both sides with respect to 
Then, setting 
But this is just a simple differential equation whose solution is:
Indeed, the solution is an irreducible solution of the form 
To find out more about the system, we can apply more linear algebra.
We apply time translation to 
By definition, since 
where 
Since this must be equal to 
Removing the sum over 
Rearranging this gives us:
We can combine the two sums into one. To do so, we sum over 
Plugging this into the equation gives us:
Finally, if we introduce 
Once again, we borrow language from linear algebra.
We can imagine a vector 
The only way this can be satisfied is if the determinant of 
Energies
We conclude this section with a discussion of the energies of the SHO. In a most general case, an undamped and unforced SHO obeys the equation of motion:
where 
The kinetic energy of the system is given by:
The potential energy of the system is given by:
For the generalized mass and spring constant to be valid, their dimensions must be set such that