TExcelTAD
Home › Calculus Essentials › Second-Order Linear Equations

Second-Order Linear Equations

Second-order linear equations with constant coefficients, ay′′+by′+cy=0ay'' + by' + cy = 0, describe anything that bounces back toward a rest position: springs, pendulums at small angles, circuits, and the spring-based cameras and UI animations in games. A guess of the form erte^{rt} reduces them to a quadratic equation, and the three kinds of roots give the three kinds of motion.

The characteristic equation

Try y=erty = e^{rt}. Then y′=rerty' = re^{rt} and y′′=r2erty'' = r^2 e^{rt}, and the equation becomes

(ar2+br+c)⋅ert=0⇒ar2+br+c=0(ar^2 + br + c) \cdot e^{rt} = 0 \quad\Rightarrow\quad ar^2 + br + c = 0

This characteristic equation is an ordinary quadratic (see polynomials and roots). Its discriminant D=b2−4acD = b^2 - 4ac picks the shape of the general solution:

Roots General solution Behaviour
D>0D > 0: two real r1≠r2r_1 \ne r_2 y=C1er1t+C2er2ty = C_1 e^{r_1 t} + C_2 e^{r_2 t} sums of exponentials, no oscillation
D=0D = 0: one repeated rr y=(C1+C2t)erty = (C_1 + C_2 t)e^{rt} the fastest non-oscillating return
D<0D < 0: r=α±βir = \alpha \pm \beta i y=eαt(C1cos⁡βt+C2sin⁡βt)y = e^{\alpha t}(C_1 \cos \beta t + C_2 \sin \beta t) oscillation inside an eαte^{\alpha t} envelope

The complex case uses Euler's formula eiβt=cos⁡βt+isin⁡βte^{i\beta t} = \cos \beta t + i\sin \beta t (see complex numbers). Two constants means two starting values, usually y(0)y(0) and y′(0)y'(0).

python · try it yourself
import sympy as sp

t = sp.symbols("t")
y = sp.Function("y")
for b, c in [(5, 6), (4, 4), (2, 5)]:
    r = sp.symbols("r")
    roots = sp.roots(r**2 + b * r + c, r)
    sol = sp.dsolve(y(t).diff(t, 2) + b * y(t).diff(t) + c * y(t))
    print(f"y'' + {b}y' + {c}y = 0   roots {roots}")
    print("   ", sol.rhs)
y'' + 5y' + 6y = 0   roots {-2: 1, -3: 1}
    (C1 + C2*exp(-t))*exp(-2*t)
y'' + 4y' + 4y = 0   roots {-2: 2}
    (C1 + C2*t)*exp(-2*t)
y'' + 2y' + 5y = 0   roots {-1 - 2*I: 1, -1 + 2*I: 1}
    (C1*sin(2*t) + C2*cos(2*t))*exp(-t)

SymPy writes the roots as a dictionary {root: multiplicity}. The three lines show the three rows of the table: −2 and −3; −2 twice; −1±2i-1 \pm 2i. SymPy likes to factor: (C1+C2e−t)e−2t(C_1 + C_2 e^{-t})e^{-2t} is just C1e−2t+C2e−3tC_1 e^{-2t} + C_2 e^{-3t}.

The damped spring

A mass mm on a spring of stiffness kk, with a damper (friction) of strength cc, obeys Newton's second law:

mx′′=−kx−cx′  ⟺  mx′′+cx′+kx=0mx'' = -kx - cx' \quad\iff\quad mx'' + cx' + kx = 0

Two numbers describe the motion:

natural frequencyω0=k/m(rad/s, how fast it would oscillate without damping)damping ratioζ=c2mk(how strongly the damper fights the motion)\begin{aligned} &\text{natural frequency} & \omega_0 &= \sqrt{k/m} && \text{(rad/s, how fast it would oscillate without damping)} \\ &\text{damping ratio} & \zeta &= \frac{c}{2\sqrt{mk}} && \text{(how strongly the damper fights the motion)} \end{aligned}
ζ\zeta Name What you see
0 undamped oscillates forever, x=Acos⁡(ω0t+φ)x = A\cos(\omega_0 t + \varphi)
0<ζ<10 < \zeta < 1 underdamped overshoots, rings, settles
1 critically damped fastest return without overshoot
>1> 1 overdamped slow creep back, no overshoot

Let's plot all three damped cases for m=1m = 1, k=4k = 4 (so ω0=2\omega_0 = 2) starting at x=1x = 1 at rest:

python · try it yourself
import numpy as np
import matplotlib.pyplot as plt
from scipy.integrate import solve_ivp

m, k = 1.0, 4.0
ts = np.linspace(0, 6, 601)
plt.figure(figsize=(6, 4))
for c in [1.0, 4.0, 8.0]:
    zeta = c / (2 * np.sqrt(m * k))
    sol = solve_ivp(lambda t, s: [s[1], (-k * s[0] - c * s[1]) / m],
                    (0, 6), [1.0, 0.0], t_eval=ts, rtol=1e-9, atol=1e-12)
    x = sol.y[0]
    plt.plot(ts, x, label=f"c = {c:g}, ζ = {zeta:g}")
    print(f"ζ = {zeta:4.2f}: lowest x = {x.min():7.4f},  x(3) = {x[300]:7.4f}")
plt.axhline(0, color="0.7", lw=0.8)
plt.xlabel("t (s)"); plt.ylabel("x"); plt.legend(); plt.title("Damped spring, m = 1, k = 4")
ζ = 0.25: lowest x = -0.4443,  x(3) =  0.1723
ζ = 1.00: lowest x =  0.0001,  x(3) =  0.0174
ζ = 2.00: lowest x =  0.0432,  x(3) =  0.2158

The underdamped spring (ζ=0.25\zeta = 0.25) swings well past 0 to the negative side. The critically damped one never crosses zero and is the closest to rest at t=3t = 3. The overdamped one is "safe" but sluggish.

Game camera springs

A follow camera that snaps instantly to the player feels harsh, and one that glides with plain damping feels floaty. Game code often treats the camera as a mass on a spring attached to the target: acceleration=ω02(target−x)−2ζω0v\text{acceleration} = \omega_0^2 (\text{target} - x) - 2\zeta\omega_0 v. Here ω0\omega_0 sets the speed of the response and ζ=1\zeta = 1 gives a quick, overshoot-free follow (Unity's SmoothDamp is built on the same critically damped idea).

python · try it yourself
def follow(zeta, omega=8.0, dt=1 / 60, seconds=1.5):
    x, v, target = 0.0, 0.0, 10.0          # the player teleports to 10
    peak, log = 0.0, {}
    for frame in range(1, int(seconds / dt) + 1):
        a = omega**2 * (target - x) - 2 * zeta * omega * v
        v += a * dt                        # semi-implicit Euler:
        x += v * dt                        # update v first, then x with the new v
        peak = max(peak, x)
        if frame in (15, 30, 60, 90):
            log[frame] = x
    return peak, log

for zeta in [0.3, 1.0]:
    peak, log = follow(zeta)
    marks = "  ".join(f"f{f}: {x:6.3f}" for f, x in log.items())
    print(f"ζ = {zeta}: max x = {peak:6.3f}   {marks}")
ζ = 0.3: max x = 13.648   f15: 10.709  f30: 12.585  f60:  9.736  f90:  9.899
ζ = 1.0: max x =  9.997   f15:  6.229  f30:  9.065  f60:  9.949  f90:  9.997

With ζ=0.3\zeta = 0.3 the camera overshoots to about 13.6, more than a third of the jump past the target, and swings back below 10; with ζ=1\zeta = 1 it arrives smoothly and stays within a hair of 10. How we step the equation (semi-implicit Euler at a fixed 1/601/60 s) is the subject of physics integration in game loops.

Forced motion, in one paragraph

With a driving force, ay′′+by′+cy=f(t)ay'' + by' + cy = f(t), the general solution is "any one particular solution" plus the homogeneous solution above. For example y′′+y=3y'' + y = 3 has the particular solution y=3y = 3, so y=3+C1cos⁡t+C2sin⁡ty = 3 + C_1 \cos t + C_2 \sin t. When the force oscillates at the system's own frequency, as in y′′+y=cos⁡ty'' + y = \cos t, the response grows like tsin⁡tt\sin t: resonance, the reason bridges and washing machines need damping.

In software

  • Animation springs: spring-based UI libraries (React Spring, SwiftUI's .spring, Android's SpringAnimation) expose stiffness and damping, or directly a damping ratio and a response time.
  • Game feel: camera follow, weapon sway, procedural recoil and jiggle bones are tuned with ω0\omega_0 and ζ\zeta.
  • Control systems: a PD controller (force=−kp⋅error−kd⋅error′\text{force} = -k_p \cdot \text{error} - k_d \cdot \text{error}') is a damped spring; robotics and drone code tune it to be near critical damping.
  • Optimisation: gradient descent with momentum on a quadratic loss behaves like a damped spring, which explains its overshoot and oscillation (gradient descent).

Exercises

Exercise 1: Real roots

Solve y′′−y′−6y=0y'' - y' - 6y = 0 with y(0)=1y(0) = 1 and y′(0)=8y'(0) = 8.

Answer

y=2e3t−e−2ty = 2e^{3t} - e^{-2t}.

Solution
r2−r−6=(r−3)(r+2)=0⇒r=3,−2y=C1e3t+C2e−2ty(0)=C1+C2=1y′(0)=3C1−2C2=8⇒5C1=10, C1=2, C2=−1\begin{aligned} r^2 - r - 6 &= (r - 3)(r + 2) = 0 \quad\Rightarrow\quad r = 3, -2 \\ y &= C_1 e^{3t} + C_2 e^{-2t} \\ y(0) &= C_1 + C_2 = 1 \\ y'(0) &= 3C_1 - 2C_2 = 8 \quad\Rightarrow\quad 5C_1 = 10,\ C_1 = 2,\ C_2 = -1 \end{aligned}

Exercise 2: Classify the damping

A 0.5 kg mass hangs on a spring with k=50k = 50 N/m. Find ω0\omega_0 and the damper strength cc that makes it critically damped. What is ζ\zeta if c=2c = 2?

Answer

ω0=10\omega_0 = 10 rad/s; critical damping at c=10c = 10 N·s/m; with c=2c = 2, ζ=0.2\zeta = 0.2 (underdamped).

Solution
ω0=k/m=50/0.5=100=10 rad/sζ=c2mk=c225=c10ζ=1  ⇒  c=10;c=2  ⇒  ζ=0.2\begin{aligned} \omega_0 &= \sqrt{k/m} = \sqrt{50/0.5} = \sqrt{100} = 10\ \text{rad/s} \\ \zeta &= \frac{c}{2\sqrt{mk}} = \frac{c}{2\sqrt{25}} = \frac{c}{10} \\ \zeta &= 1 \;\Rightarrow\; c = 10; \qquad c = 2 \;\Rightarrow\; \zeta = 0.2 \end{aligned}

Exercise 3: Complex roots

Solve y′′+6y′+13y=0y'' + 6y' + 13y = 0 with y(0)=2y(0) = 2, y′(0)=0y'(0) = 0, and check it with SymPy.

Answer

y=e−3t(2cos⁡2t+3sin⁡2t)y = e^{-3t}(2\cos 2t + 3\sin 2t).

Solution
r2+6r+13=0⇒r=−6±36−522=−3±2iy=e−3t(C1cos⁡2t+C2sin⁡2t)y(0)=C1=2y′(0)=−3C1+2C2=0⇒C2=3\begin{aligned} r^2 + 6r + 13 &= 0 \quad\Rightarrow\quad r = \frac{-6 \pm \sqrt{36 - 52}}{2} = -3 \pm 2i \\ y &= e^{-3t}(C_1 \cos 2t + C_2 \sin 2t) \\ y(0) &= C_1 = 2 \\ y'(0) &= -3C_1 + 2C_2 = 0 \quad\Rightarrow\quad C_2 = 3 \end{aligned}
python · try it yourself
import sympy as sp

t = sp.symbols("t")
y = sp.Function("y")
ode = y(t).diff(t, 2) + 6 * y(t).diff(t) + 13 * y(t)
print(sp.dsolve(ode, ics={y(0): 2, y(t).diff(t).subs(t, 0): 0}))
Eq(y(t), (3*sin(2*t) + 2*cos(2*t))*exp(-3*t))

Exercise 4: Tune a camera

A designer wants the camera spring from this lesson to be critically damped with ω0=5\omega_0 = 5. Write the acceleration formula with numbers, and say what happens if they double ζ\zeta.

Answer

a=25(target−x)−10va = 25(\text{target} - x) - 10v. With ζ=2\zeta = 2 (a=25(target−x)−20va = 25(\text{target} - x) - 20v) the camera is overdamped: no overshoot, but slower to arrive.

Solution
a=ω02(target−x)−2ζω0vω0=5, ζ=1:a=25(target−x)−10vζ=2:a=25(target−x)−20v\begin{aligned} & & a &= \omega_0^2 (\text{target} - x) - 2\zeta\omega_0 v \\ &\omega_0 = 5,\ \zeta = 1{:} & a &= 25(\text{target} - x) - 10v \\ &\zeta = 2{:} & a &= 25(\text{target} - x) - 20v \end{aligned}

The characteristic roots for ζ=2\zeta = 2 are r=−ω0(ζ±ζ2−1)=−5(2±1.732)r = -\omega_0(\zeta \pm \sqrt{\zeta^2 - 1}) = -5(2 \pm 1.732), i.e. −1.34 and −18.66. The slow root −1.34 dominates, so the gap shrinks like e−1.34te^{-1.34t} instead of the critical (1+5t)e−5t(1 + 5t)e^{-5t}.

Test yourself

The characteristic equation of y′′+4y′+4y=0y'' + 4y' + 4y = 0 has a double root r=−2r = -2. What is the general solution?

  1. C1e−2t+C2e2tC_1 e^{-2t} + C_2 e^{2t}
  2. (C1+C2t)e−2t(C_1 + C_2 t)e^{-2t}
  3. C1cos⁡2t+C2sin⁡2tC_1 \cos 2t + C_2 \sin 2t
  4. Ce−4tCe^{-4t}

What does a damping ratio ζ=1\zeta = 1 give a spring camera?

  1. Endless oscillation
  2. Overshoot then ringing
  3. The fastest return to the target without overshoot
  4. No movement at all

Which roots does r2+2r+10=0r^2 + 2r + 10 = 0 have?

  1. −1±3i-1 \pm 3i
  2. 1±3i1 \pm 3i
  3. −2 and −5
  4. −1±9i-1 \pm 9i