Textbooks/The Mathematics of Machines/Chapter 8
8Differential equations
Version 1 · Technically checked (automated checks only) · 4 source lessons · 8 practice items
Introduction
Many machines are described not by a formula for their output but by a rule for how it changes: the rate of cooling depends on the temperature difference, a spring's acceleration depends on its stretch. This chapter writes those rules as differential equations, solves the simplest ones by hand, and steps the rest forward numerically with Euler's method and RK4, watching for error and instability.
Explanation
This chapter is built from 4 School lessons. Each part below is the lesson's own explanation; open the lesson for its predict-and-discover activities.
8.1 Rate equations and exponential decay
A hot drink cools fastest when it is hottest. A capacitor discharges fastest when it is fullest. Write that sentence as an equation and the solution writes itself.
Writing the equation
RC discharge: the current through R is V/R and it drains the capacitor: C·dV/dt = −V/R, so dV/dt = −V/(RC), τ = RC. Newton's cooling: heat flow is proportional to the temperature difference, so dT/dt = −k(T − Tₐ). Both: rate ∝ distance from equilibrium.
The time constant
τ (seconds or minutes) sets the speed. After 1τ, 37% of the initial difference remains; after 3τ, 5%; after 5τ, under 1%. Engineers call a first-order system 'settled' after about 4–5τ. For R = 10 kΩ and C = 100 µF, τ = 1 s.
Why the solution must be exponential
Only one family has a rate proportional to its value: e^(kt), from week 3's chain rule. So once you see 'rate ∝ amount', you can write the exponential solution straight away, then fit k (week 9). The equation also gives the units: k is per second, so kt has no units, as an exponent must.
Derivation: Solving dy/dt = −ky
Model: the rate of decrease is proportional to the amount: dy/dt = −k·y, k > 0, with y(0) = y₀.
Separate variables (for y > 0): (1/y) dy = −k dt.
Integrate both sides: ln y = −kt + C.
Exponentiate: y = e^C·e^(−kt). At t = 0, y = e^C = y₀, so y(t) = y₀·e^(−kt).
Check by differentiating: dy/dt = y₀·(−k)·e^(−kt) = −k·y ✓.
Time constant τ = 1/k: y(τ) = y₀e⁻¹ ≈ 0.368y₀. Half-life: e^(−kt) = ½ gives t½ = ln 2/k = τ·ln 2.
Cooling: let u = T − Tₐ; then du/dt = dT/dt = −k·u, so T(t) = Tₐ + (T₀ − Tₐ)e^(−kt).
Common mix-ups
- After one time constant the quantity has halved.
✓ After τ it is at 37%; it halves after τ·ln 2 ≈ 0.69τ. - The drink cools towards 0 °C.
✓ It cools towards the room temperature Tₐ: only the difference decays.
Open the full lesson: Rate equations and exponential decay →
8.2 Euler's method and step-size error
Most differential equations have no formula solution. So computers cheat: take the slope now, step forward a little, repeat. When does that cheating go badly wrong?
The method
Know the state yₙ at time tₙ. Compute the slope f(tₙ, yₙ) from the equation. Step: yₙ₊₁ = yₙ + h·f(tₙ, yₙ), tₙ₊₁ = tₙ + h. Repeat. That is all, and it is exactly how the week 4 forward difference is used in reverse.
Accuracy: first order
Euler's global error ∝ h. To get ten times more accurate, take ten times more steps. Check any simulation by halving h: if the answer changes noticeably, the step was too large. Better methods (such as Runge–Kutta) reach error ∝ h⁴ for a little more work per step.
Stability: a separate danger
Accuracy and stability are different. Too large a step can make a decaying system grow without limit. For dy/dt = −y/τ the limit is h < 2τ, and smooth results need h < τ. Fast processes (small τ) therefore force small steps even when you only care about slow ones.
Derivation: Euler's step factor, its error and its stability limit
For dy/dt = −k·y, one Euler step gives yₙ₊₁ = yₙ + h·(−k·yₙ) = (1 − kh)·yₙ.
The exact solution multiplies by e^(−kh) = 1 − kh + (kh)²/2 − … each step. The difference per step is about (kh)²/2: the local error ∝ h².
To reach a fixed time T takes T/h steps, so the errors add to about (T/h)·h² ∝ h: the global error is first order. Halve h, halve the error.
After n steps yₙ = y₀(1 − kh)ⁿ. This decays only if |1 − kh| < 1, that is 0 < kh < 2, or h < 2τ.
For 1 < kh < 2 the factor is negative: the numerical solution overshoots zero every step while shrinking. For kh > 2 it grows without bound: numerical instability, not physics.
Common mix-ups
- If a simulation blows up, the physical system is unstable.
✓ It may be numerical instability from too large a step. Halve h and see if it persists. - A stable simulation is an accurate one.
✓ Stable only means it does not explode. Accuracy needs a convergence check.
8.3 Linear ODEs you can solve by hand
Tap a wine glass, pluck a guitar string, release a car's suspension: one second-order equation describes them all. What does it predict?
First order
dx/dt = −kx has solution x(t) = x₀ e^{−kt}. The time constant τ = 1/k is the time to fall to about 37%. After 5τ it is under 1%. RC circuits, cooling and many sensor lags are first-order.
Second order
m x″ + c x′ + k x = 0 needs two initial conditions (position and velocity). Its behaviour is set by ω_n (how fast it wants to oscillate) and ζ (how strongly it is damped). Engineers often design for ζ around 0.6–0.7: quick, with little overshoot.
Benchmarks for numerics
With c = 0, m = k = 1 and x(0) = 1, x′(0) = 0, the exact solution is x = cos t and the energy ½x′² + ½x² stays at 0.5 for ever. That exact answer is what week 7 uses to measure integrator errors.
Derivation: Solving m x″ + c x′ + k x = 0
Try x = e^{rt}. Then x′ = r e^{rt}, x″ = r² e^{rt}, and the equation becomes (m r² + c r + k) e^{rt} = 0.
So r solves the characteristic equation m r² + c r + k = 0: r = (−c ± √(c² − 4mk)) / (2m).
Write ω_n = √(k/m) and ζ = c/(2√(km)). Then r = −ζω_n ± ω_n√(ζ² − 1).
ζ > 1 (overdamped): two negative real roots, x = A e^{r₁t} + B e^{r₂t}. ζ = 1 (critical): x = (A + Bt) e^{−ω_n t}.
ζ < 1 (underdamped): r = −ζω_n ± iω_d with ω_d = ω_n√(1 − ζ²), so x = e^{−ζω_n t}(A cos ω_d t + B sin ω_d t).
A and B come from the initial position and velocity. By linearity, any combination of solutions is a solution (week 1).
Common mix-ups
- More damping always makes a system settle faster.
✓ Beyond critical damping, it creeps more slowly. Fastest settling without overshoot is at ζ = 1. - The damped frequency equals the natural frequency.
✓ ω_d = ω_n√(1 − ζ²) is a little lower, noticeably so for large ζ.
8.4 Euler, semi-implicit Euler and RK4
Simulate a frictionless spring with Euler's method and it gains energy from nowhere. Is the physics wrong, or the arithmetic?
The three methods
For y′ = f(t, y):
- Explicit Euler: yₙ₊₁ = yₙ + h f(tₙ, yₙ). One slope, at the start.
- Semi-implicit (symplectic) Euler for x′ = v, v′ = a(x): vₙ₊₁ = vₙ + h a(xₙ), then xₙ₊₁ = xₙ + h vₙ₊₁.
- RK4: k₁ = f(tₙ, yₙ), k₂ = f(tₙ + h/2, yₙ + h k₁/2), k₃ = f(tₙ + h/2, yₙ + h k₂/2), k₄ = f(tₙ + h, yₙ + h k₃); yₙ₊₁ = yₙ + (h/6)(k₁ + 2k₂ + 2k₃ + k₄).
Accuracy versus structure
RK4 is far more accurate per step: with h = 0.1 over t = 10 its position error is about 4×10⁻⁶, against about 0.6 for explicit Euler. But RK4 still slowly loses energy (with h = 0.2 over 10 periods, about 0.4998 instead of 0.5). Semi-implicit Euler is only first-order accurate, yet its energy never drifts away. For long orbital or molecular simulations, that structure can matter more than raw accuracy.
Cost
Count function evaluations, the expensive part for real models. RK4 costs four per step, Euler one. RK4 with step 4h therefore costs the same as Euler with step h, and is still usually far more accurate.
Derivation: Why explicit Euler gains energy on the oscillator
Write x″ = −x as x′ = v, v′ = −x. Energy E = ½(x² + v²) is exactly conserved by the true solution.
Explicit Euler: xₙ₊₁ = xₙ + h vₙ, vₙ₊₁ = vₙ − h xₙ.
Then xₙ₊₁² + vₙ₊₁² = xₙ² + 2h xₙvₙ + h²vₙ² + vₙ² − 2h xₙvₙ + h²xₙ² = (1 + h²)(xₙ² + vₙ²).
So Eₙ = (1 + h²)ⁿ E₀: exponential growth for any h > 0. Over a fixed time T = nh, Eₙ ≈ E₀ e^{hT}, which tends to E₀ only as h → 0.
Semi-implicit Euler updates v first and uses the new v for x. It conserves a slightly modified energy exactly, so its energy error stays bounded for all time (it is symplectic).
Common mix-ups
- If the simulation looks smooth, it is accurate.
✓ Euler's spiral looks smooth and is completely wrong about energy. Compare with an exact or converged answer. - Higher order always wins.
✓ It wins on accuracy for smooth problems; structure (energy, stability) can matter more over long times.
Worked examples
Rate equations and exponential decay: example 1
R = 10 kΩ, C = 100 µF, V(0) = 9 V. Find τ and V at 2 s.
Solution
τ = RC = 10⁴ × 10⁻⁴ = 1 s. V(2) = 9e⁻² = 1.22 V.
Euler's method and step-size error: example 1
dV/dt = −V/2, V(0) = 5 V, h = 0.5 s. Take two Euler steps.
Solution
Factor 1 − 0.5/2 = 0.75. V₁ = 3.75 V, V₂ = 2.8125 V. Exact V(1) = 5e^(−0.5) = 3.033 V. Error 0.22 V; with h = 0.25 it would be about half.
Linear ODEs you can solve by hand: example 1
m = 2 kg, k = 50 N/m, c = 4 N·s/m. Find ω_n, ζ and ω_d.
Solution
ω_n = √(50/2) = 5 rad/s. ζ = 4/(2√100) = 0.2. ω_d = 5√(1 − 0.04) ≈ 4.90 rad/s. Underdamped; the envelope decays like e^{−1·t}.
Euler, semi-implicit Euler and RK4: example 1
One explicit Euler step for x′ = v, v′ = −x from (1, 0) with h = 0.1.
Solution
x₁ = 1 + 0.1·0 = 1, v₁ = 0 − 0.1·1 = −0.1. Energy ½(1 + 0.01) = 0.505 = 0.5 × 1.01, as the derivation predicts.
Interactive figures
Interactive figure (online). Description: In the decay-fit lab the capacitor readings fall from 9 V towards zero. In the log view, ln V against time is a straight line whose slope is −k; the best fit gives k close to 0.45 per second, so τ ≈ 2.2 s and a half-life of about 1.5 s. The readout states k, τ, half-life and the RMS error.
Interactive figure (online). Description: The Euler lab plots the exact exponential decay with Euler's points. With τ = 2 and h = 0.5 the points track the curve slightly low and the error halves when h halves. At h = 3 they zigzag about zero while shrinking; at h = 4 they oscillate with constant size; at h = 5 they zigzag and grow. The readout names the regime from h/τ.
Interactive figure (online). Description: The phase-portrait diagram plots velocity against position with direction arrows and six trajectories. Sliders set stiffness and damping; text gives the eigenvalues, the critical damping value and the type of equilibrium (centre, spiral or node).
Interactive figure (online). Description: The integrator diagram plots energy against time for explicit Euler, semi-implicit Euler (dashed) and RK4, with the exact energy 0.5 as a dashed line. Text lists each method's final energy and the Euler growth factor per step.
Laboratory
Everything runs in your browser. No kit, nothing mains-powered. Simulations are simplified educational models.
Equation Lab exploration
Equation Lab: First-order systems
Change the time constant and check that the response reaches about 63 % of its final value after one τ.
Open Equation Lab: First-order systems →Equation Lab exploration
Equation Lab: Oscillator
Vary the damping ratio and classify each response as under-, critically or over-damped.
Open Equation Lab: Oscillator →Simulation OS experiment
Simulation OS: RC charge and discharge
Compare the simulated capacitor voltage with the exact exponential at three times.
Open Simulation OS: RC charge and discharge →
Guided practice
Answers are checked on the server; wrong answers get a hint and another try. Signed in, solved items also count towards the source lesson.
- A cooling temperature difference halves every 12 minutes. What is its time constant τ, in minutes? (min)
- What percentage of the initial value remains after 5 time constants? (%)
- dV/dt = −V/τ with τ = 2 s and V(0) = 5 V. One Euler step of h = 0.5 s gives what V, in volts? (V)
- For dy/dt = −y/τ with τ = 2 s, what is the largest Euler step (in seconds) that does not blow up? (s)
- A mass–spring–damper has m = 2 kg, k = 8 N/m, c = 4 N·s/m. What is its damping ratio ζ?
- For m = 1 kg and k = 9 N/m, what damping gives critical damping?
- c = 3
- c = 6
- c = 9
- Explicit Euler on x″ = −x with h = 0.05: by what factor does the energy grow per step?
- With the same number of function evaluations, which is usually more accurate on smooth problems?
- Euler with step h
- RK4 with step 4h
- They are always equal
Engineering applications
Simulators
Every physics engine and circuit simulator steps differential equations forward. Choosing the method and step size is a trade between accuracy, stability and computing time.
Suspension and control tuning
The damping ratio of a mass–spring–damper decides whether a vehicle's suspension bounces or settles smoothly. The same second-order model describes many feedback loops.
Watch
Optional verified videos. Nothing loads from YouTube until you press play.
- Differential equations, a tourist's guide | DE1 (3Blue1Brown)
- Coding a Fourth-Order Runge-Kutta Integrator in Python and Matlab (Steve Brunton)
Chapter summary
- dy/dt = −y/τ has the solution y = y0·e^(−t/τ); after one τ about 37 % remains, after 5τ less than 1 %.
- Euler's method: y(n+1) = y(n) + h·f(t(n), y(n)). Its error per unit time shrinks in proportion to h (first order).
- For decay, Euler is stable only if h < 2τ; a large step can make the numbers explode.
- A second-order system's behaviour is set by its natural frequency ωn and damping ratio ζ.
- RK4 uses four slope evaluations per step and is fourth-order accurate; symplectic methods conserve energy better over long runs.
Glossary
- Exponential growth and decay
- A quantity decays exponentially when its rate of decrease is proportional to how much is left, giving y = y0 × e^(−t/τ).
- First-order system and time constant
- A first-order system responds to a step by approaching its new value exponentially; its time constant τ is the time to cover 63.2 % of the change.
- RC time constant
- When a capacitor charges or discharges through a resistor, the voltage changes exponentially with time constant τ = R × C.
- Damping ratio
- The damping ratio ζ describes how quickly oscillations die out in a second-order system: below 1 it oscillates, exactly 1 is critically damped, above 1 it creeps to the target without overshoot.
- Hooke's law (springs)
- For a spring within its elastic limit, the force needed to stretch or compress it is proportional to the change in length: F = k × x.
Definitions from the Field Guide.
Project: How small a step?
Simulate a cooling model dT/dt = −(T − Ta)/τ with Euler's method for three step sizes, compare each with the exact solution, and find the largest step that keeps the error below 1 °C over the run. Repeat with RK4 and compare the cost.
Deliverables
- The model with parameter values and units
- Error tables for each step size and method
- The chosen step size with justification
Keep your work in your Engineering Journal; it stays private unless you choose to share it.
References
- William E. Boyce and Richard C. DiPrima (2012). Elementary Differential Equations and Boundary Value Problems, 10th edition. Wiley.
- J. C. Butcher (2016). Numerical Methods for Ordinary Differential Equations, 3rd edition. Wiley.
- Erwin Kreyszig (2011). Advanced Engineering Mathematics, 10th edition. Wiley.
Further reading from the source lessons
- OpenStax Calculus Volume 1 (free, open textbook) ↗A complete first-year calculus text with worked examples and exercises, free to read online.
Publication record
- Version
- 1
- Status
- Technically checked (automated checks only)
- Technical review
- Automated checks only, last run 2026-11-29. No human, educator or mentor review is claimed.src/content/textbooks/textbooks.test.ts: schema, every lesson, diagram, practice item, video, Field Guide entry, lab and reference resolves; figure numbers recomputed; no practice answers in client payloads.
- Written by
- Compiled and written by the Tactiverge team with AI assistance, from Tactiverge School lessons that were themselves written with AI assistance.
- Licence
- All rights reserved by the founders unless a licence is approved.
- Corrections
- None recorded yet.Spotted a mistake? Use “Report a problem” on any chapter, or see the corrections page.