Kinetic energy
—
Adjust the system parameters, then play the animation to watch how energy shifts between the spring, mass, and damper.
—
—
—
React to changing drive frequencies by dialing in damping fast enough to keep the steady-state amplitude below the damage threshold. Each round translates the response curve into an arcade-style targeting challenge.
From automobile suspensions to seismically isolated buildings, countless machines rely on the balance between inertia, spring stiffness, and damping. A traditional damped harmonic oscillator calculator reports only a displacement value, concealing how energy sloshes between kinetic and elastic stores while friction steals a portion every cycle. This interactive version keeps the original purpose of computing motion but augments it with a canvas that shows a block bobbing on a spring. As you adjust parameters like mass or forcing amplitude, the animation and energy bars update instantly, clarifying why an overly soft shock absorber leads to bouncy rides or why a lightly damped bridge oscillates for minutes after a gust of wind.
The model treats a single degree‑of‑freedom system consisting of mass , spring constant , and viscous damping coefficient . Position and velocity are measured along the spring’s axis with the equilibrium at . Optional sinusoidal forcing can drive the oscillator. Initial conditions and set the starting state. Air resistance and structural damping are modeled with the single coefficient ; nonlinear effects, large deflections, and temperature‑dependent stiffness are ignored. All quantities use SI units: kilograms, newtons, meters, and seconds. Input validation rejects non‑finite or negative mass and spring values, and the time step is clamped between 0.001 and 0.1 s to maintain numerical stability.
The dynamics follow Newton’s second law applied to the mass: . Introducing yields a first‑order system:
, . Kinetic and potential energies are and , while the power dissipated by damping is . The work performed by the driving force accumulates as , allowing an energy balance check .
The simulator advances the state with a classical fourth‑order Runge–Kutta method. For each step of size , four derivative estimates sample the forces at the beginning, two midpoints, and the end. The weighted average updates position and velocity simultaneously. RK4 offers a good compromise between speed and accuracy; the local error scales with , so halving the step roughly reduces the global error by a factor of sixteen. Nevertheless, very stiff systems with large or may require smaller steps to avoid overshoot. The code clamps the user‑selected and recomputes the trajectory whenever inputs change, debounced by 400 ms to prevent excessive re‑simulation during typing.
Consider a 1 kg mass attached to a spring with N/m and damping kg/s. Starting from m and , with no external forcing, the simulator predicts oscillations that decay with a time constant ≈ 4 s. Running the animation with s shows the block initially move toward the origin, overshoot, and settle after a few cycles. The energy bars reveal kinetic energy peaking as the block passes equilibrium and shrinking as damping converts it to heat. Downloading the CSV confirms the analytic period of about 1.4 s derived from .
The table contrasts the baseline oscillator above with two variations: increased damping and a driven case. Values are extracted from the simulation after five seconds.
Scenario | c (kg/s) | F₀ (N) | Max |x| (m) | Energy drift (J) |
---|---|---|---|---|
Baseline | 0.5 | 0 | 0.10 | ≈0 |
Heavier damping | 2.0 | 0 | 0.04 | ≈0 |
Driven | 0.5 | 1.0 | 0.12 | <0.001 |
Doubling the damping coefficient reduces the peak displacement to 4 cm, while a modest sinusoidal drive at the natural frequency slightly increases the amplitude without introducing significant numerical energy error.
The canvas displays a horizontal spring anchored to the left wall with a colored block on the right. The block’s position corresponds to the instantaneous displacement, scaled to fit the viewport. A blue trail traces its recent path. Beneath the canvas, striped orange, blue, and gray bars show kinetic energy, spring potential energy, and cumulative dissipated energy, respectively, with text labels so color perception is unnecessary. The caption narrates time, displacement, velocity, and the small energy‑balance error. Focus the canvas with the keyboard and press the space bar to toggle play and pause. The hidden “Simulation summary” div mirrors these numbers for screen readers.
Several idealizations keep the model tractable. Damping is purely viscous and linear, whereas real shock absorbers can exhibit velocity‑squared or hysteretic behavior. The spring obeys Hooke’s law without yielding or coil bind. Forcing is limited to a single sinusoid; arbitrary waveforms or impacts are not included. The system moves only in one dimension, ignoring torsional or lateral modes. Numerical integration assumes the parameters remain constant and may lose accuracy for extremely stiff or poorly scaled inputs. Despite these simplifications, the simulator captures the essential trade‑offs that govern many engineering designs.
Ambitious users could extend the code to include nonlinear damping, piecewise spring behavior, or multiple degrees of freedom coupled in series. Plotting velocity versus displacement would generate a phase‑space portrait that highlights spiraling toward rest. Another extension is to add a second mass and spring, exploring resonance and modal beating. Because the project uses only vanilla JavaScript, editing the source to experiment with control strategies or feedback loops is straightforward. For related explorations, see the Mass‑Spring Oscillation Calculator, compare electrical analogs with the RLC Circuit Damping Calculator, or examine motion without springs in the Projectile Motion Calculator.
Standard treatments of damped oscillations appear in H. Goldstein, C. Poole, and J. Safko, Classical Mechanics, and R. C. Hibbeler, Engineering Mechanics: Dynamics. These texts discuss linear systems, energy methods, and the effect of damping on resonance. The numerical technique follows the RK4 algorithm described in any introductory computational physics resource.