19.17 Computer modelling – the simple harmonic oscillator

Before you read this, I suggest you read the first 8 paragraphs of post 18.6.

In previous posts, we have seen how differential equations (post 19.10) can be used to represent diffusion (post 19.15), the conduction of heat (post 19.15) and the behaviour of waves (post 19.12). We also saw how a differential equation could be used to describe the behaviour of a simple harmonic oscillator – a system that is constantly exchanging potential and kinetic energy with negligible energy loss (post 18.6). However, there is a completely different way of investigating systems like this, without developing differential equations.


In this post, I will illustrate this different approach by using it to investigate a simple harmonic oscillator. In the table above, a mechanical simple harmonic oscillator starts (n = 1) with potential energy U1 = 1.00 J (post 16.21). If we think of this oscillator being restored towards its undisturbed state by a spring, with spring constant k (post 16.49), then

U = (k/2)x2

where x is its displacement (post 16.49). So the initial displacement of the oscillator in the table is

x1 = (2U1/k)1/2.

If k = 200 N.m-1 then

x1 = (2 × 1/200)1/2 = 0.1 m.

At this initial position (n = 1), its kinetic energy, K1 (post), and, therefore, its speed, are both zero. We use this initial state to define a time t = 0.

I have used Microsoft Excel to create the numbers in the table to 6 decimal places – the results do not reflect the precision with which the results can be calculated; if this comment isn’t clear – see post 16.7.

Now we consider a later state (n = 2) when the oscillator has lost 0.01 J of potential energy, so that now U2 = 0.99 J. Using the same approach as previously, its position is

x2 = (2 × 0.99/200)1/2 = 0.099499 m.

This “lost” potential energy is converted to 0.01 J of kinetic energy, so now K2 = 0.01 J. For an oscillator of mass m with speed v

K = (m/2)v2

(post 16.21). If our oscillator has a mass of 1 kg, its speed is then

v2 = (2K2/m)1/2 = (2 × 0.01/1)1/2 = 0.141421 m.s-1.

During the time that the 0.01 J of potential energy was being transferred into kinetic energy, the displacement of the oscillator was (x2x1) and its average speed was (v1 + v2)/2 so that the time interval for the exchange of energy was

Δt = 2(x2x1)/ (v1 + v2) = 2(0.099499 + 0.1)/(0 + 0.141421) = 0.007089 s.

(see post 16.12). Now, the total time that has elapsed is

t2 = t1 + Δt = 0 + 0.007089 s.

In the table above, I have continued this process for stages n = 3, 4, 5, 6….. and so on. Below, you can see what happens when n is about 100.

fig 2a


When n = 101, all the potential energy has been transformed into kinetic energy. Then the displacement, x, is in the opposite direction (it has a minus sign) and kinetic energy starts to be transformed into potential energy. As before, I calculate the effects of this transformation in steps of 0.01 J.


I will continue the calculations until a time of 0.886 s has elapsed; the graph above then shows the displacement, x, plotted against time t. This graph shows that the behaviour of our oscillator repeats every 0.444 s – it has a time period (post 16.14) T = 0.444 s. (it is easier to see the exact result from a table, like the examples above.)

We could have obtained the same result by setting up the differential equation for an object bouncing on a spring and then solving it to obtain the result

T = 2π(m/k)1/2

as in post 18.11. Then, when m = 1 kg and k = 200 N.m-1,

T = 2π(1/200)1/2 = 0.444 s.

The advantage of this approach is that it gives a general result that we can use for any value of k and m.

The method used in this post is simpler, because it uses only a few simple definitions and some simple arithmetic. It shows exactly what happens when m = 1 kg and k = 200 N.m-1 but cannot provide any general results. Sometimes, especially in engineering, a specific result is all that is required then this numerical or computational approach provides everything that is needed. This approach can also be useful when it is too difficult to set up or solve a differential equation.

Usually, I prefer the differential equation approach – not only because it provides a more general result but also because it can help us to understand how we get that result.


Related posts

19.13 More about standing waves
19.11 Partial differentiation
19.10 Differential equations
18.17 Euler’s relation
18.16 The square root of minus 1
18.15 More about exponential growth
18.11 Motion in a circle, the simple harmonic oscillator and waves
18.3 Logarithms
18.2 Powers of numbers
17.42 Dimensional analysis
17.41 Units in equations
17.19 Calculating distances from speeds
17.4 Displacement, velocity and acceleration
16.7 Writing numbers


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s