TactivergeLite

Lite / Textbooks / The Mathematics of Machines / Chapter 8

8. Differential equations

Version 1 · Technically checked (automated checks only) · 4 source lessons · Full interactive version

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.

Figure 8.1. Euler's method against the exact decay (described in words)

The exact solution y = e^(−t/τ) of dy/dt = −y/τ, starting at 1, plotted from t = 0 to 2τ. Euler steps of size h = 0.5τ give 1, 0.5, 0.25, 0.125, 0.0625. At t = τ the exact value is about 0.368 and Euler gives 0.25.

Explanation

Built from 4 School lessons. Each part is the lesson's own explanation.

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
  1. Model: the rate of decrease is proportional to the amount: dy/dt = −k·y, k > 0, with y(0) = y₀.

  2. Separate variables (for y > 0): (1/y) dy = −k dt.

  3. Integrate both sides: ln y = −kt + C.

  4. Exponentiate: y = e^C·e^(−kt). At t = 0, y = e^C = y₀, so y(t) = y₀·e^(−kt).

  5. Check by differentiating: dy/dt = y₀·(−k)·e^(−kt) = −k·y ✓.

  6. Time constant τ = 1/k: y(τ) = y₀e⁻¹ ≈ 0.368y₀. Half-life: e^(−kt) = ½ gives t½ = ln 2/k = τ·ln 2.

  7. Cooling: let u = T − Tₐ; then du/dt = dT/dt = −k·u, so T(t) = Tₐ + (T₀ − Tₐ)e^(−kt).

Common mix-ups

Open the Lite 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
  1. For dy/dt = −k·y, one Euler step gives yₙ₊₁ = yₙ + h·(−k·yₙ) = (1 − kh)·yₙ.

  2. 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².

  3. 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.

  4. After n steps yₙ = y₀(1 − kh)ⁿ. This decays only if |1 − kh| < 1, that is 0 < kh < 2, or h < 2τ.

  5. 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

Open the Lite lesson: Euler's method and step-size error

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
  1. 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.

  2. So r solves the characteristic equation m r² + c r + k = 0: r = (−c ± √(c² − 4mk)) / (2m).

  3. Write ω_n = √(k/m) and ζ = c/(2√(km)). Then r = −ζω_n ± ω_n√(ζ² − 1).

  4. ζ > 1 (overdamped): two negative real roots, x = A e^{r₁t} + B e^{r₂t}. ζ = 1 (critical): x = (A + Bt) e^{−ω_n t}.

  5. ζ < 1 (underdamped): r = −ζω_n ± iω_d with ω_d = ω_n√(1 − ζ²), so x = e^{−ζω_n t}(A cos ω_d t + B sin ω_d t).

  6. A and B come from the initial position and velocity. By linearity, any combination of solutions is a solution (week 1).

Common mix-ups

Open the Lite lesson: Linear ODEs you can solve by hand

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):

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
  1. Write x″ = −x as x′ = v, v′ = −x. Energy E = ½(x² + v²) is exactly conserved by the true solution.

  2. Explicit Euler: xₙ₊₁ = xₙ + h vₙ, vₙ₊₁ = vₙ − h xₙ.

  3. Then xₙ₊₁² + vₙ₊₁² = xₙ² + 2h xₙvₙ + h²vₙ² + vₙ² − 2h xₙvₙ + h²xₙ² = (1 + h²)(xₙ² + vₙ²).

  4. 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.

  5. 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

Open the Lite lesson: Euler, semi-implicit Euler and RK4

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, in words

Figure 8.2 from Rate equations and exponential decay

Choose the capacitor data. Turn on the log view: the points should lie on a straight line. Adjust k until the model line matches, then press Best fit. Read τ and the half-life. Why is ln(V) straight when V is curved?

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.

Figure 8.3 from Euler's method and step-size error

Start with τ = 2 and h = 0.5: read the error table and its ratio. Now try h = 1, 2, 2.5 and watch the regime change from smooth, to overshooting, to oscillating forever, to unstable. Change τ: does the boundary move with h/τ?

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/τ.

Figure 8.4 from Linear ODEs you can solve by hand

In 'Mass–spring–damper' mode, set k = 4 and sweep c from 0 to 6. Watch the trajectories change from circles (c = 0) to spirals to straight-in curves. Note the value of c where the eigenvalues become real, and compare with 2√k.

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).

Figure 8.5 from Euler, semi-implicit Euler and RK4

In 'Oscillator energy', set h = 0.2 and run 10 periods. Which curve drifts up, which stays bounded, which slowly sinks? Halve h and see which drift shrinks fastest.

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.

The interactive versions are in the full chapter.

Laboratory

These run in a browser on the full site (they need a faster connection). Simulations are simplified educational models.

Practice

Each question links to its Lite lesson, where your answer is checked on our server and a wrong answer gets a hint. Answers are never sent to your device.

  1. A cooling temperature difference halves every 12 minutes. What is its time constant τ, in minutes?
    Answer it in “Rate equations and exponential decay”
  2. What percentage of the initial value remains after 5 time constants?
    Answer it in “Rate equations and exponential decay”
  3. dV/dt = −V/τ with τ = 2 s and V(0) = 5 V. One Euler step of h = 0.5 s gives what V, in volts?
    Answer it in “Euler's method and step-size error”
  4. For dy/dt = −y/τ with τ = 2 s, what is the largest Euler step (in seconds) that does not blow up?
    Answer it in “Euler's method and step-size error”
  5. A mass–spring–damper has m = 2 kg, k = 8 N/m, c = 4 N·s/m. What is its damping ratio ζ?
    Answer it in “Linear ODEs you can solve by hand”
  6. For m = 1 kg and k = 9 N/m, what damping gives critical damping?
    Answer it in “Linear ODEs you can solve by hand”
  7. Explicit Euler on x″ = −x with h = 0.05: by what factor does the energy grow per step?
    Answer it in “Euler, semi-implicit Euler and RK4”
  8. With the same number of function evaluations, which is usually more accurate on smooth problems?
    Answer it in “Euler, semi-implicit Euler and RK4”

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)

Streaming video uses a lot of data. Everything you need is in the text.

Summary

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/τ). Field Guide
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. Field Guide
RC time constant
When a capacitor charges or discharges through a resistor, the voltage changes exponentially with time constant τ = R × C. Field Guide
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. Field Guide
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. 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

Write it up on paper or in your own notes. Lite never stores what you write.

References

Further reading from the lessons

← 7. Accumulation and integrals9. Probability and uncertainty →