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.
The model treats a point mass attached to a massless spring with constant and a linear damper with coefficient . The block starts at displacement with zero velocity and may experience a sinusoidal driving force of amplitude and angular frequency . 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.
Newtonās second law balances forces on the mass:
with . Kinetic and potential energies follow
, .
The damper converts mechanical energy into heat at a rate , whose integral accumulates as the gray bar.
The coupled firstāorder system for and 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 at time and step size , RK4 evaluates four derivative estimates ⦠and combines them as
The methodās local truncation error scales with , making it stable for modest step sizes. The input field lets you clamp 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 to the initial total energy.
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 rad/s and the period 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 N and rad/s, the system resonates: despite damping, the forcing replenishes lost energy and the amplitude stabilizes near 0.2Ā m.
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.
Scenario | m (kg) | c (NĀ·s/m) | Steady Amplitude (m) | ĪE after 5 s (%) |
---|---|---|---|---|
Baseline | 1 | 0.5 | 0.20 | 0.8 |
Heavy damping | 1 | 2 | 0.08 | 0.5 |
Lighter mass | 0.5 | 0.5 | 0.35 | 1.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.
The canvas shows a wall on the left, a zigāzag spring, and a square mass whose position represents . 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.
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.
Extensions could include multiple masses coupled by springs, nonlinear restoring forces, or stochastic driving terms that mimic thermal noise. Plotting phase space ( versus ) 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.
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.