ENع
←Equations of motion
Lesson 06 · Modelling systems

Writing the equation of motion: springs, masses and dampers

15 min12 steps5 questionsIntermediate
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.

You'll learn to

Tick what you feel confident about. These self-checks do not affect your lesson score.

Fig 6 · Interactive
01 / 12

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.
Loading figure…
or ← →
Read the lesson step by step
  1. 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.
  2. 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 −.
  3. 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).
  4. 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.
  5. 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.
  6. 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 N
  7. Newton'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 power
  8. Put 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.
  9. 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.305
  10. Where 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 N
  11. Change 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.
  12. 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])

Quiz Unlocks after the last step.