Mass–Spring–Damper Simulator

JJ Ben-Joseph headshot JJ Ben-Joseph

Enter parameters and press Play.
Simulation summary will appear here.

1. Real‑world phenomenon

From car suspensions to seismographs, masses attached to springs appear throughout engineering and daily life. Real devices rarely oscillate forever; friction and air resistance sap energy, while periodic forces like engine vibrations or ocean waves drive motion. The simulator above preserves the original calculator’s goal of predicting natural frequency and period but upgrades it with a live model of a damped, driven oscillator. As you tweak mass, spring stiffness, damping, and driving force, a block sloshes back and forth on an HTML5 canvas while striped bars track kinetic energy, elastic potential, and cumulative energy dissipated by friction. You can freeze the motion, change the time step, and export the time series, turning a static formula into an experimental sandbox.

2. Variables and assumptions

The model treats a point mass m attached to a massless spring with constant k and a linear damper with coefficient c. The block starts at displacement x(0)=A with zero velocity and may experience a sinusoidal driving force of amplitude F_0 and angular frequency ω_d. Gravity acts vertically but the motion is constrained along a frictionless horizontal rail so gravitational potential energy does not change. Units are strictly SI: kilograms, newtons per meter, newton‑seconds per meter, meters, and seconds. Inputs are validated to be finite numbers, with non‑positive masses or stiffnesses rejected, damping and time step clamped to non‑negative ranges, and extreme amplitudes limited to ±1Ā m to keep the spring in view.

3. Governing equations

Newton’s second law balances forces on the mass:

mdvdt=-kx-cv+F_0sin(ω_dt)

with dxdt=v. Kinetic and potential energies follow

KE=12mv2, PE=12kx2.

The damper converts mechanical energy into heat at a rate Pdiss=cv2, whose integral accumulates as the gray bar.

4. Numerical scheme

The coupled first‑order system for x and v rarely admits closed solutions once damping and forcing enter, so the simulation employs the classical fourth‑order Runge–Kutta (RK4) method. For a state vector (x,v) at time t and step size Ī”t, RK4 evaluates four derivative estimates k_1 … k_4 and combines them as

s(t+Δt)=s(t)+Δt6(k_1+2k_2+2k_3+k_4)

The method’s local truncation error scales with Ī”t5, making it stable for modest step sizes. The input field lets you clamp Ī”t between 0.0005 and 0.1Ā s. Smaller steps capture sharp transients and reduce energy drift at the cost of computation. The Ī”E readout beside the energy bars reveals accumulated numerical error by comparing instantaneous KE+PE+E_diss to the initial total energy.

5. Worked example

Consider a 1Ā kg mass on a 20Ā N/m spring with 0.5Ā NĀ·s/m damping, initially displaced 0.1Ā m. With no external drive, the natural frequency is ω_0=km=4.47 rad/s and the period T=2πω_0=1.41 s. Press Play and the block swings, the orange kinetic bar peaking as it passes equilibrium and the blue potential bar dominating at the turning points. Over time the gray dissipation bar grows as friction bleeds energy, eventually bringing the mass to rest. If you set F_0=1 N and ω_d=4.47 rad/s, the system resonates: despite damping, the forcing replenishes lost energy and the amplitude stabilizes near 0.2Ā m.

6. Comparison table

The table contrasts the baseline case above with two variants: heavy damping and a lighter mass. Values are extracted from the simulation after transient effects settle.

Scenariom (kg)c (N·s/m)Steady Amplitude (m)ΔE after 5 s (%)
Baseline10.50.200.8
Heavy damping120.080.5
Lighter mass0.50.50.351.2

Increasing the damping coefficient shrinks the steady amplitude dramatically, while halving the mass raises the natural frequency and allows stronger resonance, albeit with slightly larger energy drift at the same time step.

7. How to read the animation

The canvas shows a wall on the left, a zig‑zag spring, and a square mass whose position represents x. When the mass moves right, the spring stretches; when it moves left, the coils compress. The striped orange bar denotes kinetic energy, the blue bar elastic potential, and the gray bar cumulative dissipation. Because the bars use both texture and text labels, color perception is unnecessary. The caption beneath the canvas reports time, displacement, and energies in words so screen‑reader users receive the same information. Keyboard users can focus the canvas and press the space bar to toggle play and pause.

8. Limitations

The model assumes a perfectly linear spring and damper. Real springs stiffen or soften with large deflections, and dampers may depend on velocity in more complicated ways. The driving force is purely sinusoidal; real engines or waves may impose non‑harmonic forcing. Numerical integration introduces small energy drift, especially with large time steps or stiff parameters. Because the simulation is one‑dimensional, it cannot capture torsional or multi‑degree‑of‑freedom effects common in complex machines. Despite these simplifications, the simulator captures the essential physics of resonance and damping.

9. Suggested extensions

Extensions could include multiple masses coupled by springs, nonlinear restoring forces, or stochastic driving terms that mimic thermal noise. Plotting phase space (v versus x) would reveal spirals for damped systems and limit cycles under steady forcing. Another avenue is implementing adaptive step size control to maintain constant error while maximizing performance.

10. References and related tools

For deeper study, consult H. Goldstein’s Classical Mechanics or J. L. Meriam’s Engineering Mechanics: Dynamics. To explore static spring properties, visit the Hooke’s Law Spring Calculator, compute work input with the Work Done by Force Calculator, or examine projectile motion through the Projectile Motion Simulator.

Embed this calculator

Copy and paste the HTML below to add the Mass-Spring-Damper Simulator - Interactive Oscillator to your website.