Mechanics  ·  21 April 2026↻ Updated 17 Aug 2026

Simple Harmonic Motion Simulator — Spring and Oscillation

Simple harmonic motion (SHM) is the most fundamental type of oscillation in physics. It occurs whenever a system is displaced from equilibrium and experiences a restoring force proportional to the displacement. Springs, pendulums (for small angles), sound waves, and even atoms vibrating in a crystal lattice all exhibit SHM.

Understanding SHM is essential for waves, optics, quantum mechanics, and electrical circuits — because oscillation is everywhere. The simulator below starts with a 1 kg mass on a 10 N/m spring pulled 1 m from equilibrium, which oscillates with a period of about 1.99 s. Switch between the time series and the phase portrait to see the same motion two different ways.

Period

1.99 s

10 N/m
1 kg
1 m
0

What Makes Motion "Simple Harmonic"?

Plenty of things in the world go back and forth. Only some of them are simple harmonic, and the distinction is precise.

The Restoring Force Is the Whole Story

SHM requires one condition, and everything else follows from it: the force pulling the system back toward equilibrium must be proportional to how far it has been displaced, and directed opposite to that displacement.

F=kxF = -kx

The minus sign is the important part. Pull the mass right and the spring pulls left; push it left and the spring pushes right. The force always opposes the displacement, so the system can never settle anywhere except equilibrium — and because the force grows in exact proportion to displacement, the motion that results is a pure sine wave rather than some lopsided wobble.

A mass bouncing on a trampoline is oscillating, but the restoring force is not proportional to displacement, so the motion is not simple harmonic. A ball rolling in a parabolic bowl is. The test is always the same: is the restoring force linear in the displacement?

Why Amplitude Doesn't Change the Period

This is the property that made SHM the basis of timekeeping for three centuries, and it is genuinely counter-intuitive: pull the mass twice as far and it still takes the same time to complete an oscillation.

Drag the amplitude slider in the simulator and watch the period refuse to budge.

The reason is a cancellation. Doubling the amplitude doubles the distance the mass must travel — but it also doubles the restoring force at every point, which doubles the acceleration, which makes the mass move proportionally faster. The extra distance is covered at proportionally higher speed, and the two effects cancel exactly. Only a force that is linear in displacement produces this cancellation, which is why the property is special to SHM rather than to oscillation generally.

This is called isochronism, and Galileo is said to have noticed it watching a swinging lamp in Pisa cathedral.

The Equation of Motion

For a mass mm on a spring with spring constant kk, applying Newton's second law gives:

mx¨=kxx¨=ω02xm\ddot{x} = -kx \quad \Rightarrow \quad \ddot{x} = -\omega_0^2 x

where the natural angular frequency is:

ω0=km\omega_0 = \sqrt{\frac{k}{m}}

Reading the Equation Before Solving It

x¨=ω02x\ddot{x} = -\omega_0^2 x says something worth pausing on: the acceleration is proportional to the position, with a minus sign. We need a function whose second derivative is itself, negated and scaled. Sine and cosine are exactly those functions — which is why SHM produces sinusoids, not as an approximation but as an exact consequence.

The solution is:

x(t)=Acos(ω0t+ϕ)x(t) = A\cos(\omega_0 t + \phi)

where AA is the amplitude and ϕ\phi is the initial phase — the constant that says where in the cycle the motion started.

Notice what is absent from ω0=k/m\omega_0 = \sqrt{k/m}: the amplitude. The frequency depends only on the stiffness of the spring and the mass attached to it. That is isochronism falling straight out of the algebra.

Key Quantities

QuantityFormulaUnit
Angular frequencyω0=k/m\omega_0 = \sqrt{k/m}rad/s
PeriodT=2π/ω0=2πm/kT = 2\pi/\omega_0 = 2\pi\sqrt{m/k}s
Frequencyf=1/Tf = 1/THz
Max velocityvmax=Aω0v_{max} = A\omega_0m/s
Max accelerationamax=Aω02a_{max} = A\omega_0^2m/s²

Velocity and acceleration are the derivatives of position, so each is a quarter-cycle ahead of the last. Velocity peaks as the mass flies through equilibrium, where displacement is zero. Acceleration peaks at the turning points, where the mass is momentarily stationary and the spring is most stretched. The mass is fastest where the force on it is zero, and motionless where the force is greatest — a good check on whether the picture has clicked.

Where Does the Energy Go?

An undamped oscillator conserves total energy, trading it back and forth between two forms:

E=12kx2potential+12mv2kinetic=12kA2E = \underbrace{\tfrac{1}{2}kx^2}_{\text{potential}} + \underbrace{\tfrac{1}{2}mv^2}_{\text{kinetic}} = \tfrac{1}{2}kA^2

At the turning points, all of it is elastic potential energy. At equilibrium, all of it is kinetic. Everywhere in between it is a mixture, and the total never changes.

Because energy depends on A2A^2, doubling the amplitude quadruples the stored energy — even though, as we saw, it does not change the period at all.

With the simulator's defaults (k = 10 N/m, A = 1 m) the total energy is 12(10)(1)2=5\tfrac{1}{2}(10)(1)^2 = 5 J, held constant for as long as the damping ratio stays at zero.

What Does the Phase Portrait Show?

The phase portrait plots velocity against displacement rather than either one against time. It throws away the clock and shows the state of the oscillator instead.

For undamped SHM this traces a closed ellipse. Closed is the key word: the system returns to exactly the same combination of position and velocity every cycle, forever. Nothing is lost.

Introduce damping and the ellipse becomes an inward spiral, each loop a little smaller as energy drains away, winding down toward the origin — the state of zero displacement and zero velocity.

Phase portraits become indispensable for systems too complicated to solve on paper; the Lorenz attractor is what one looks like when the motion is chaotic rather than periodic.

How Does Damping Change the Motion?

Real oscillators lose energy to friction and air resistance. Adding a damping term γx˙\gamma\dot{x} gives:

x¨+γx˙+ω02x=0\ddot{x} + \gamma\dot{x} + \omega_0^2 x = 0

The damping ratio ζ=γ/(2ω0)\zeta = \gamma/(2\omega_0) characterises the decay:

  • ζ=0\zeta = 0 — undamped. Oscillates forever at ω0\omega_0. An idealisation, but a useful one.
  • 0<ζ<10 < \zeta < 1 — underdamped. Still oscillates, but the amplitude decays exponentially inside an envelope. A plucked guitar string, a child's swing left alone.
  • ζ=1\zeta = 1 — critically damped. Returns to equilibrium in the shortest possible time without overshooting. This is the target for car suspension and door closers.
  • ζ>1\zeta > 1 — overdamped. Returns without oscillating, but sluggishly — the extra resistance slows the approach. A door closer set too tight.

The critically damped case is the one engineers usually want, and it is a genuinely delicate target: slightly under and the system rattles, slightly over and it crawls. Push the ζ slider slowly through 1 to watch the oscillation disappear.

How Is a Pendulum Related to SHM?

A simple pendulum is not truly simple harmonic — but for small swings it is close enough that the difference rarely matters.

The restoring force on a pendulum bob is mgsinθ-mg\sin\theta. That sinθ\sin\theta is not proportional to θ, so strictly the motion is not SHM. But for small angles, sinθθ\sin\theta \approx \theta (in radians), and the force becomes effectively linear. Under that approximation the pendulum behaves like a spring with k=mg/Lk = mg/L, giving:

T=2πLgT = 2\pi\sqrt{\frac{L}{g}}

The mass cancels out entirely — a heavy bob and a light one on the same string swing at the same rate.

The approximation is better than it has any right to be. At a 15° swing the true period exceeds the formula by only 0.43%; even at 30° the error is just 1.7%. Beyond that the real period grows noticeably longer than predicted, and a pendulum clock swinging too widely runs slow.

Worked Examples

Worked Example

Example 1 — Period of a spring-mass system

A mass of 0.5 kg is attached to a spring with constant k = 20 N/m. What is the period of oscillation?

ω0=km=200.5=406.32 rad/s\omega_0 = \sqrt{\frac{k}{m}} = \sqrt{\frac{20}{0.5}} = \sqrt{40} \approx 6.32 \text{ rad/s}

T=2πω0=2π6.320.99 s1 sT = \frac{2\pi}{\omega_0} = \frac{2\pi}{6.32} \approx 0.99 \text{ s} \approx 1 \text{ s}

The mass completes one full oscillation roughly every second.

Worked Example

Example 2 — Maximum velocity and acceleration

For the same system (k = 20 N/m, m = 0.5 kg) with amplitude A = 0.1 m, find the maximum speed and maximum acceleration.

vmax=Aω0=0.1×6.320.63 m/sv_{max} = A\omega_0 = 0.1 \times 6.32 \approx 0.63 \text{ m/s}

amax=Aω02=0.1×40=4 m/s2a_{max} = A\omega_0^2 = 0.1 \times 40 = 4 \text{ m/s}^2

Both maxima occur at different points: vmaxv_{max} at the equilibrium position (x=0x = 0), amaxa_{max} at the turning points (x=±Ax = \pm A).

Worked Example

Example 3 — Energy in the oscillator

The same system (k = 20 N/m, m = 0.5 kg, A = 0.1 m). What is the total energy, and how fast is the mass moving when it is halfway to the turning point (x = 0.05 m)?

Total energy: E=12kA2=12(20)(0.1)2=0.1 JE = \tfrac{1}{2}kA^2 = \tfrac{1}{2}(20)(0.1)^2 = 0.1 \text{ J}

At x = 0.05 m, the potential energy is U=12kx2=12(20)(0.05)2=0.025 JU = \tfrac{1}{2}kx^2 = \tfrac{1}{2}(20)(0.05)^2 = 0.025 \text{ J}

so the kinetic energy is 0.10.025=0.0750.1 - 0.025 = 0.075 J, and

v=2Km=2(0.075)0.5=0.30.55 m/sv = \sqrt{\frac{2K}{m}} = \sqrt{\frac{2(0.075)}{0.5}} = \sqrt{0.3} \approx 0.55 \text{ m/s}

At half the amplitude the mass still has 75% of its energy as kinetic and is moving at 87% of top speed — the energy is concentrated near the turning points far more sharply than intuition suggests.

Worked Example

Example 4 — Length of a seconds pendulum

A "seconds pendulum" ticks once per second, meaning a full back-and-forth period of 2 s. How long must it be, taking g = 9.81 m/s²?

Rearranging T=2πL/gT = 2\pi\sqrt{L/g}:

L=g(T2π)2=9.81(22π)20.994 mL = g\left(\frac{T}{2\pi}\right)^2 = 9.81\left(\frac{2}{2\pi}\right)^2 \approx 0.994 \text{ m}

Just under a metre — which is why grandfather clocks are the height they are. A 1.000 m pendulum gives a period of 2.006 s instead of 2.000 s, and that 0.3% error accumulates: such a clock would lose about 4.4 minutes per day.

Frequently Asked Questions

Explore more simulations

Every concept on PhysicStuff has an interactive simulation. No login, no setup required.