Simulation

Spring-Mass System

OscillationsMass-spring systems

A mass on a spring demonstrating Hooke's law and undamped simple harmonic motion — adjust spring constant, mass, initial velocity, and amplitude to explore conservation of energy.

Objective

Confirm that an undamped mass-on-a-spring obeys simple harmonic motion driven by Hooke's law F = −k·x, and verify the closed-form period T = 2π√(m/k). Measure the displacement and velocity readouts against the predicted sinusoid x(t) = A·cos(ωt) with ω = √(k/m), and check that total mechanical energy ½k·x² + ½m·v² remains constant throughout the swing. The spring is treated as massless, perfectly Hookean, and free of damping or friction.

Setup

  1. Press Reset to return the mass to its starting displacement and zero out the Time readout. The Displacement and Velocity readouts repopulate from the current slider values, and the Period T readout shows the predicted T for the chosen k and m.
  2. Set the Spring Constant slider to 10 N/m. This is a moderate stiffness that produces a clearly visible swing without slamming the mass against the canvas edges at the chosen amplitude.
  3. Set the Mass slider to 1.0 kg. With k = 10 N/m, this gives a clean angular frequency ω = √(10/1) ≈ 3.162 rad/s and a period close to 2 s, easy to time by eye against the readouts.
  4. Set the Initial Velocity slider to 0.00 m/s. Releasing the mass from rest at peak displacement makes the predicted motion a pure cosine, so the analysis section can compare against x(t) = A·cos(ωt) directly.
  5. Set the Amplitude slider to 2.0 m. The mass starts 2 m below equilibrium (positive displacement is downward) and the dashed equilibrium line marks x = 0 on the canvas.
  6. Press Start. The mass oscillates vertically along the centerline; the Time, Displacement, and Velocity readouts update live, and a fading amber trail traces recent positions for visual comparison.

Analytical Prediction

For an undamped spring-mass system, Newton's second law combined with Hooke's law F = −k·x gives m·ẍ = −k·x, whose solution is x(t) = A·cos(ωt + φ) with angular frequency ω = √(k/m) and period T = 2π√(m/k). Released from rest at x = A, the phase φ = 0, so x(t) = A·cos(ωt) and v(t) = −A·ω·sin(ωt). With k = 10 N/m, m = 1.0 kg, A = 2.0 m, v₀ = 0:

ω=√(k/m)
=√(10 / 1)
3.162 rad/s
T=2π / ω
=2π / √10
1.987 s
v_max=A · ω
=2.0 · 3.162
6.325 m/s
E=½ · k · A²
=½ · 10 · 4
=20.0 J

Energy oscillates between purely elastic (PE = 20 J at x = ±A, KE = 0) and purely kinetic (KE = 20 J at x = 0, PE = 0). At the first quarter-period, t ≈ 0.497 s, the mass should cross equilibrium with velocity ≈ −6.325 m/s.

Results Analysis

Once the run is underway, sample the readouts at four reference times. Near t = 0.00 s the Displacement reads ≈ 2.000 m and Velocity ≈ 0.000 m/s. Near t ≈ 0.50 s (one quarter period) Displacement should pass through ≈ 0 m and Velocity should peak near −6.325 m/s. Near t ≈ 0.99 s (half period) Displacement reaches ≈ −2.000 m with Velocity ≈ 0. Near t ≈ 1.99 s the mass returns to the starting state, completing one cycle. The Period T readout should already display ≈ 1.99 s, matching the timed return. Confirm energy conservation by computing ½k·x² + ½m·v² at any sampled instant — for x ≈ 1.414 m and v ≈ ±4.472 m/s the sum is 10.0 + 10.0 = 20.0 J, equal to the initial ½k·A². Agreement within roughly 0.5% over several cycles confirms the SHM model.

Source of Error

What this sim does NOT model: the spring's own mass and inertia, gravity (the system is treated as horizontal, so weight does not enter the equation), air drag, internal damping in the spring material, non-Hookean stiffening at large amplitudes, or finite spring travel limits. The mass is a point on an ideal Hookean spring with no dissipation. The closed forms F = −k·x and T = 2π·√(m/k) assume the same idealizations, so they cancel rather than contributing to the residual amplitude or period. The remaining gap between prediction and readouts is therefore purely numerical, not physical.

Further Exploration