Physics

Spring Force & Oscillation Calculator (Hooke's Law)

Restoring force, stored energy and oscillation period for a mass on an ideal spring.

Real Larzscript running in your browser74 automated checksOpen source · MITNo sign-up · your inputs never leave your device

Hooke's law and spring oscillation

Restoring force (kx)
—
Stored energy (½kx²)
—
Oscillation period
—
Frequency
—
Show the Larzscript program that just ran
Run a calculation to see the exact program.

This is the real program the page sent to the Larzscript interpreter (compiled to WebAssembly) in your browser. The library it imports is the same code the automated tests check.

The formulas

F = -kx    PE = ½kx²    T = 2π√(m/k)

The minus sign in F = -kx means the force always points back toward equilibrium; this page reports its magnitude. The period formula assumes an ideal, massless spring and no friction.

Worked example, computed above

k = 200 N/m, x = 0.1 m, m = 1 kg: force 20 N, stored energy 1 J, period 0.4443 s.

What is verified

The period is checked against the closed form T = 2π√(m/k) to 9 decimal digits, and length round-trips through the pendulum formulas below confirm the same square-root relationship holds — see tests/test_mechanics.lz.

Frequently asked questions

What is Hooke's law?

F = kx — the restoring force of an ideal spring is proportional to how far it is stretched or compressed. A spring with k = 200 N/m stretched 0.1 m pushes back with 20 N.

How much energy is stored?

PE = ½kx² — the same 0.1 m stretch on a 200 N/m spring stores 1 J, recoverable as kinetic energy when released.

What is the oscillation period?

For a mass on a spring, T = 2π√(m/k), independent of amplitude (for an ideal spring). A 1 kg mass on a 200 N/m spring oscillates with period 0.4443 s — swing it a little or a lot, the period barely changes.

Does a stiffer spring oscillate faster or slower?

Faster — period shrinks as 1/√k, so quadrupling stiffness halves the period. A heavier mass does the opposite: period grows as √m.

Every number on this page is computed by the open-source larzscript-physics library (mechanics, physmath), written in Larzscript, and checked against independent references in its test suite. How it is verified →