Writing the equation of motion: springs, masses and dampers
About this lesson
Before you can control a system you need its equation. Take a cart tied to a wall by a spring and a damper, draw every force on it, apply Newton's second law and get m·ẍ + b·ẋ + k·x = F(t). Then watch that equation, run in three lines of Python, move the cart, and see how one coefficient changes the motion.
A cart, a spring, a damper
A 2 kg cart rolls on a smooth table. A spring and a damper tie it to a wall. A damper is a piston in oil, like a door closer: it resists motion. We want an equation that predicts where the cart goes.
mass m = 2 kg (the cart) spring k = 50 N/m (how stiff) damper b = 4 N·s/m (how much it resists speed) Goal: an equation for x(t), the cart's position over time. Its solution is what the cart will do.
Read the lesson step by step
A cart, a spring, a damper
A 2 kg cart rolls on a smooth table. A spring and a damper tie it to a wall. A damper is a piston in oil, like a door closer: it resists motion. We want an equation that predicts where the cart goes.
mass m = 2 kg (the cart) spring k = 50 N/m (how stiff) damper b = 4 N·s/m (how much it resists speed) Goal: an equation for x(t), the cart's position over time. Its solution is what the cart will do.Choose what to measure
Let x be how far the cart has moved right from where it rests with the spring relaxed, in metres. Right is positive. Its velocity is ẋ = dx/dt and its acceleration is ẍ = d²x/dt².
x position, m (0 = spring relaxed) ẋ velocity, m/s dx/dt ẍ acceleration, m/s² d²x/dt² Pick the sign once and keep it: every force to the right is +, every force to the left is −.The input: a steady push
From t = 0 we push the cart to the right with a steady force F = 10 N and keep pushing. The force is the system's input. The position x(t) is its output: the thing we want to predict.
input F(t) = 10 N for t ≥ 0 (a step) output x(t), metres The equation we are after links the two: given F(t), it tells us x(t).The spring pulls back
A spring pulls back in proportion to its stretch: force = −kx (Hooke's law). With k = 50 N/m and the cart at x = 0.1 m, the spring pulls 5 N to the left.
spring force = −k·x = −50 × 0.1 = −5 N (to the left) Twice the stretch, twice the pull. It depends on position only.The damper fights speed
A damper pushes against the velocity, not the position: force = −bẋ. With b = 4 N·s/m and the cart moving right at 0.5 m/s, it pushes 2 N to the left. A cart standing still feels nothing from it.
damper force = −b·ẋ = −4 × 0.5 = −2 N (to the left) It depends on speed only. It turns motion into heat in the oil.Draw every force
Draw the cart alone with every force on it: a free-body diagram. Along x there are three: the push F to the right, the spring −kx and the damper −bẋ. Gravity and the table cancel, up and down.
forces on the cart, along x (+ = right): push +F = +10 N spring −k·x = −5 N damper −b·ẋ = −2 N ───────────────────── total = +3 NNewton's second law
Total force equals mass times acceleration: F − kx − bẋ = mẍ. Move every x term to the left: mẍ + bẋ + kx = F(t). That is the equation of motion, a linear second-order differential equation.
m·ẍ = F − k·x − b·ẋ m·ẍ + b·ẋ + k·x = F(t) equation of motion right now: ẍ = (10 − 5 − 2) / 2 = 1.5 m/s² second order: the highest derivative is ẍ linear: x, ẋ, ẍ appear only to the first powerPut in the numbers
With our parts: 2ẍ + 4ẋ + 50x = 10. Divide by m: ẍ + 2ẋ + 25x = 5. The two numbers that shape the motion are ωn = √(k/m) = 5 rad/s and ζ = b/(2√(km)) = 0.2.
2ẍ + 4ẋ + 50x = 10 ẍ + 2ẋ + 25x = 5 standard form ẍ + 2ζωn·ẋ + ωn²·x = F/m ωn = √(k/m) = √25 = 5 rad/s ζ = b/(2√(k·m)) = 4/20 = 0.2 ζ < 1: it will overshoot and ring.Let the equation run
The code steps the equation forward every millisecond. The cart overshoots to 0.305 m at 0.64 s, swings back and settles. Watch the arrows: the spring force follows x, the damper force follows speed.
# the equation of motion, stepped every 1 ms m, b, k, F = 2, 4, 50, 10 x, v, dt, peak = 0.0, 0.0, 0.001, 0.0 for n in range(6000): # 6 s a = (F - k*x - b*v) / m v = v + a*dt x = x + v*dt peak = max(peak, x) print(round(peak, 3)) # 0.305Where it settles
Once the cart stops, ẋ and ẍ are zero, so the equation leaves kx = F: x = F/k = 10/50 = 0.2 m. The spring alone holds the push. The damper only decides how the cart gets there.
at rest: ẍ = 0, ẋ = 0 m·0 + b·0 + k·x = F x = F / k = 10 / 50 = 0.2 m peak 0.305 m at 0.64 s (53% past 0.2 m) spring at the peak 15.3 NChange a part, change a number
Fit a stronger damper, b = 20 N·s/m. One coefficient changes: 2ẍ + 20ẋ + 50x = 10, and ζ becomes 1, called critical damping. The cart now creeps up to 0.2 m with no overshoot.
2ẍ + 20ẋ + 50x = 10 ζ = 20 / 20 = 1 critical damping b = 4 overshoots to 0.305 m, rings b = 20 no overshoot; 0.192 m after 1 s Same parts, same law: only b moved.Toward a transfer function
If the cart starts at rest, the Laplace transform turns ẍ into s²X(s) and ẋ into sX(s): (2s² + 4s + 50)X(s) = F(s). The ratio X(s)/F(s) = 1/(2s² + 4s + 50) is the cart's transfer function.
zero initial conditions: ẍ → s²·X(s) ẋ → s·X(s) (2s² + 4s + 50)·X(s) = F(s) X(s) 1 ──── = ───────────── F(s) 2s² + 4s + 50 import control as ct G = ct.tf([1], [2, 4, 50])
5 quick questions
Choose one answer per question. You can change your choices before checking them.
01A spring with k = 50 N/m is stretched by x = 0.04 m. What force does it put on the cart?
Hooke's law: force = −k·x = −50 × 0.04 = −2 N. The minus sign means it pulls back toward the rest position.
02The cart is momentarily still at its furthest point, x = 0.305 m. What force does the damper put on it at that instant?
A damper's force is −b·ẋ. It depends on velocity only, so when the cart is momentarily still the damper pushes with nothing.
03Newton's second law on the cart's free-body diagram gives which equation?
Total force F − k·x − b·ẋ equals m·ẍ. Moving the x terms to the left gives m·ẍ + b·ẋ + k·x = F(t): mass goes with acceleration, damping with velocity, stiffness with position.
04With m = 2 kg, k = 50 N/m and a steady push F = 10 N, where does the cart end up, whatever the damper?
At rest ẋ = ẍ = 0, so the equation leaves k·x = F and x = F/k = 10/50 = 0.2 m. The damper only shapes the way there (b = 4 overshoots to 0.305 m first).
05With the cart starting at rest, what is the transfer function X(s)/F(s) of m·ẍ + b·ẋ + k·x = F(t)?
With zero initial conditions the Laplace transform turns ẍ into s²X(s) and ẋ into sX(s), giving (m·s² + b·s + k)X(s) = F(s). Divide: X/F = 1/(m·s² + b·s + k).
Glossary
- Equation of motion
- The differential equation that links a system's input (here the force F) to its output (the position x). For the cart: m·ẍ + b·ẋ + k·x = F(t).
- Free-body diagram
- A drawing of one body on its own with every force that acts on it, each as an arrow with its direction. Newton's second law is applied to it.
- Hooke's law
- An ideal spring pulls back in proportion to its stretch: force = −k·x, where k (N/m) is the spring's stiffness.
- Viscous damper
- A part, like a piston in oil, whose force opposes velocity: force = −b·ẋ, where b (N·s/m) is the damping coefficient.
- Natural frequency ωn
- √(k/m), in rad/s: how fast the mass would swing on the spring with no damping. 5 rad/s here.
- Damping ratio ζ
- b/(2√(k·m)): below 1 the response overshoots and rings, at 1 (critical damping) it rises as fast as it can without overshoot.
- Second-order system
- A system whose equation's highest derivative is the second, like ẍ. It needs two numbers to start: position and velocity.
Notes and sources
- The cart, spring and damper are illustrative values (m = 2 kg, k = 50 N/m, b = 4 or 20 N·s/m, F = 10 N), chosen so ωn = 5 rad/s and ζ = 0.2 exactly. The frozen moment used to explain each force (x = 0.1 m, ẋ = 0.5 m/s) is an example state; every curve and every number while the equation runs is the exact solution of the equation of motion for these values.
- The model is ideal: a massless linear spring, a viscous damper whose force is exactly proportional to speed, and no friction from the table. Real parts only follow these laws over a limited range; the model is useful because it is simple and close enough.
- The Python steps the equation forward 1 ms at a time (semi-implicit Euler). It reaches the same peak, 0.305 m, as the exact solution drawn in the plot.
- The Laplace step is taught in the Circuits lesson "Circuit analysis with the Laplace transform"; the solution shapes (overshoot, critical damping) in the Maths lesson "Second-order differential equations and damping". The transfer function gets its own lesson, "The transfer function of a system".
- N. S. Nise, Control Systems Engineering, 8th ed., Wiley (ch. 2, translational mechanical systems)
- K. Ogata, Modern Control Engineering, 5th ed., Pearson (§3-2 mathematical modeling of mechanical systems)
- G. F. Franklin, J. D. Powell, A. Emami-Naeini, Feedback Control of Dynamic Systems, 8th ed., Pearson (ch. 2, Dynamic models)
- MIT OpenCourseWare 16.06 Principles of Automatic Control (S. Hall)
- MIT OpenCourseWare 6.302 Feedback Systems (Roberge, Dawson, Lundberg)
- python-control documentation: control.tf (transfer functions from coefficient lists)
Quiz Unlocks after the last step.