This is a tutorial / article on Simple Harmonic Motion. It describes an oscillating motion in physics, which is defined by certain conditions. It is decently math-intensive, so as long as you know:
- Decent calculus (Extending as far as the chain rule)
- Exponential functions
- Trigonometric functions
- Very basic kinematics (Mathematics of motion)
- Hooke’s law (Easy to learn if you don’t know it)
- Basic rearranging of equations (Not necessary, but will aid understanding)
You should be fine to proceed, given you’re somewhat comfortable with these concepts. If you don’t fully understand them, feel free to read on anyway. You might learn something, and you don’t need to know everything on this list to understand the topic to a basic level.
In this tutorial, certain letters / symbols will be used to define certain variables in the system. Things in this list will be defined later into the tutorial. If you forget what they mean, just refer to them here:
- a is acceleration (ms⁻²) (vector)
- v is velocity (ms⁻¹) (vector)
- x is displacement (m) (vector)
- λ is damping coefficient (no units) (scalar)
- ω is angular frequency (radian s⁻¹) (scalar)
- T is time period (s) (scalar)
- f is frequency (s⁻¹) (scalar)
- k is spring constant (Nm⁻¹) (scalar)
- m is mass (kg) (scalar)
- ϵ is phase constant (radian) (scalar)
- A is amplitude (m) (scalar)
- F is force (N) (vector)
A “simple harmonic system” is a system involving motion which can be described as simple harmonic motion.
Understanding conditions and concepts
As mentioned, there are certain conditions that must be met for a system to be modeled as simple harmonic motion. These conditions are:
- Acceleration of the system must be proportional to the displacement.
- Acceleration acts toward an equilibrium position, or otherwise opposite to the displacement.
These are the things to identify when trying to find out if a system can be modeled with simple harmonic motion. Two of these systems will be outlined in this tutorial, these are: a mass on a spring, and a simple pendulum. This tutorial will use a mass on a spring to derive and teach the equations needed. The way to model a pendulum will not be outlined in this tutorial, however the way to do so is practically the same as a spring, so you can use the same equations. I’ll leave that as an exercise for you .
For now, we won’t consider damping, but it will be covered later in the tutorial since it is relatively easy to add.
To understand how we may begin to model these systems, we must be able to know how these systems move, and we will be outlining this with a mass on a spring.
This is a model of a mass on a spring oscillating, and a graph adjacent to show its displacement over time. As you can see, it follows a sine / cosine curve. You will see later where this comes in.
We must first learn an important concept with simple harmonic motion, known as angular frequency, denoted with the Greek letter omega (ω). If we separate the parts of its name, we can get a good idea of what it is. Frequency describes how many oscillations occur within a given time period, usually a second. Angular suggests a link with angles. Putting both of these definitions together gives us:
Angular Frequency (ω): Change in angle over a given time period.
There are two formulae which can be used to calculate angular frequency from this definition. Since it is a proportion of how much an angle has changed over time, we can express it as a ratio between a full rotation (2π), and the time period (T). We can get two formulae out of this, and it is because there is a link between time period and frequency. Since time period gives us the time it takes for an oscillation to happen, and frequency is how many oscillations occur in a second, we can define time period in the following manner:
These will be important to remember for later when we define angular frequency.
Before we discuss the formula for angular frequency, let’s begin to think about what this looks like in terms of a graph. Consider a sine / cosine curve, it’s derived from a circle. In fact, a point moving around the circumference in an anti-clockwise direction (or counterclockwise, whatever you prefer). This is, in fact, true and it is how we can understand angular frequency, consider the following diagram:
If you notice, the displacement of the mass on the end of the spring (now hidden for easier viewing), is following an exact sine / cosine curve and can be seen as a one-dimensional projection onto the y-axis. The angular frequency in this diagram is how many radians the point on the circumference of the circle rotates around the circumference within 1 second. With all of this in mind, we can finally say that the formula for angular frequency is:
or, by the other time period definition:
We are nearly ready to define the displacement based on these definitions. There are two more things we need to consider. Up first, amplitude (A). This is a very simple concept to understand. The amplitude is defined as:
Amplitude (A): the maximum displacement from the equilibrium position.
For example, if you were to pull down a spring 10 centimeters from it’s resting state, the amplitude would be 10 centimeters, since you would break the laws of physics (given no external forces) if it were any larger than that, since you would be creating energy.
The final thing (without considering damping) we need to think about is something called the phase constant (ϵ). This is a value which exists to align the beginning of the graph of the displacement of the mass on the spring against time. In other words, imagine you were measuring this motion, and you started your timer a second after you let the spring go. It would be part-way through an oscillation, and to represent that with an equation, we just shift the graph by the phase constant. It isn’t particularly important if you plan to use this information to program something.
Equations of Simple Harmonic Motion
Finally, we can define displacement of the mass on the spring. Using what we know already (from prior definitions, and calculus), we can begin by stating that:
Since we can replace the proportionality symbol by introducing a constant, we can say:
but in this case k is not the spring constant. Let us make it our goal to find k in this scenario. To do this, we must understand exactly what acceleration is, in terms of a derivative. Consider that acceleration is the change in velocity over time. To get velocity from displacement, we take the derivative of the displacement equation, since it’s the change in displacement over time. Therefore, we can define acceleration as the second derivative of displacement. Therefore the next step is:
Now to resolve this for displacement, we would have to solve a second-order linear ordinary differential equation - solving this is beyond the scope of this tutorial. I will skip to the equation of displacement. If you really want to see how this is solved, there are likely sources online. Onward, the displacement equation is:
There are other solutions to this problem but this is the one I will use in this tutorial. From here, we are going to differentiate this with respect to time to find the equation of velocity. I encourage you to try this yourself if you can. The equation is:
From here, let’s differentiate once more with respect to time to arrive at the equation for acceleration:
Now, if you notice, the equation for displacement is embed within the acceleration equation:
and so, we arrive back where we began:
We can now see the link very closely between acceleration and displacement within a simple harmonic system. Acceleration always acts in the opposite direction of the displacement, or in other words, when the mass is below the equilibrium position, the acceleration acts upward, and vice versa.
Time Period of a Simple Harmonic System
There was a very important fact that was not mentioned in the previous sections that are important.
Every single object that can vibrate has a preferred frequency it would wish to vibrate at if left with no external forces, known as its natural frequency. This has a very large implication in terms of motion:
For a Simple Harmonic System where the system is left to oscillate, the time period is always constant, and therefore be calculated, even when damping is involved in the system.
Here’s an example. Consider the mass on the spring, If you were to pull it down very far from its equilibrium position, the time taken for it to oscillate one full cycle would be the exact same as if you pulled it down a very short distance. For a spring, we can define the time period in terms of it’s spring constant (k). We are going to derive this using the equation for Hooke’s Law, which states that force applied to a spring is proportional to the extension of the spring, where the constant of proportionality is the spring constant.
Let us consider Newton’s second law of motion, Force is equal to mass (m) multiplied by acceleration (a):
From this, we can substitute this equation into our first equation to arrive at:
We know from before that acceleration (a) and displacement (x) have a ratio when the system can be described using simple harmonic motion:
We rearrange our equation above involving mass, acceleration, the spring constant and displacement, to get:
and substituting the ratio above:
and naturally, the minus from both sides will cancel out in the next step. If you remember back to when we defined angular frequency as an equation, we had a form involving time period, which is what we’re aiming for. Let’s first proceed by square rooting both sides:
As you’d expect, this is the way to calculate angular frequency if you were to model a spring using code, since you can define mass as well as the spring constant yourself. Moving on, we remember the equation of angular frequency before to be:
We can now equate these equations:
Now we take the reciprocal of both sides and multiply both sides by 2π to arrive at our equation for time period:
however, for a pendulum, it’s a little more complicated to arrive at the time period equation. So I’ll just provide the equation here:
Where L is the length of the string the mass is hanging from, and g is the acceleration due to gravity. This is normally taken to be ≈ 9.81m⁻².
As implied from the start, we can clearly see that the time period depends on two factors:
- The spring constant of the spring
- The mass of the object hanging on the spring
that is, for a mass on a spring.
Damping is a method which removes energy from the system, causing it to slow down and eventually stop at the equilibrium position, and the rate at which this occurs is exponential and occurs at a specific rate defined by the damping coefficient (λ).
The way we can show how great the damping is, is through an exponential function:
As you’ll see later, the amount that the max amplitude is decreased is proportional to this and the initial maximum amplitude.
For some context on how damped the system becomes over time in relation to the damping coefficient, look at the gif below:
As you can very clearly see, as the damping coefficient increases, the steepness of the curve (gradient) increases, so the higher the damping coefficient, the quicker the system will come to rest.
Okay, so how do we incorporate this into our motion before? Well, it’s quite simple actually. We just multiply our displacement by the exponential function above, which gets us:
I won’t take you through the pain of differentiating this to get velocity and acceleration, because they’re rather horrid equations and if you can’t do it yourself, feel free to message me on the forums or just search it online.
Our spring with damping now looks like this (λ = 0.5, m = 0.09, k = 9.4):
As you can see, the max amplitude it reaches is decreasing over time, and this is proportional to the original amplitude. Eventually, the max amplitude becomes pretty much zero (It never actually hits zero but it gets infinitely close to the point where it’s negligible).
So you can see how the displacement and the damping function are related, look at this picture:
The green line is the exact same line as from the (λ = 0.5) line from the gif showing how the curve changes with the damping coefficient changing, but multiplied by the initial amplitude (A). The blue line is the graph of displacement on the y-axis, and time on the x-axis, of the mass on a spring. As you can see, the rate at which the curve decreases is now exactly the same as the rate at which the displacement decreases. This means we’re successful in damping the system.
Application of equations
As you may have noticed, so far this seems to be only applicable for one-dimensional springs, or they can only go up and down. However, there is a solution to this, using vectors.
If you consider the initial amplitude to be a two or three-dimensional vector, you can get a two or three-dimensional displacement / velocity / acceleration respectively, and therefore position it accordingly.
This also means you would need to get the distance on all axes to the equilibrium position for the amplitude, but it would not be too difficult. Using only the information I’ve written in this article I’ve made a spring as an example result:
My code is rather messy, so I will explain how I did it here.
Creating a 3D spring
Firstly, I had the original spring length set by default and calculated the equilibrium position, by translating downward that length from the part the spring is attached to. Then I calculated the amplitude by finding how far the mass deviated from the equilibrium position with vectors as described above. Then all I did, after defining constants such as mass, spring constant, damping coefficient, I calculated the displacement from the equilibrium position with the equation:
Finally, since I can now find the position the spring will move to at any given time, you just animate it as you’d expect to do, and allow time to elapse with a RenderStep, or however you’d like.
You can really use these equations in whatever you want to, obviously, they will only make sense if they follow the conditions outlined in this article. Try making something creative and post it here, I’d love to see it.
I conclude my tutorial / article on Simple Harmonic Motion. If you have any further questions, or feel that I missed something important, feel free to post them on the thread below, or send me a private message on the forums and I will try to respond as quickly as I can. I hope you learned something! Special thanks to @sircfenner for proofreading this as well.
Thanks for reading,