TactivergeLite

Lite / Textbooks / Applied Engineering Mathematics / Chapter 6

6. Numerical methods and their errors

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

Introduction

A computer only ever approximates an integral or a differential equation, so the engineer's job is to know how good the approximation is. This chapter measures error properly: the trapezoid rule's predictable error, local and global error and the observed order of a method, stability limits that make explicit methods explode on stiff problems, and convergence studies that turn 'it looks fine' into evidence.

Figure 6.1. Error against step size (described in words)

A log-log plot of the global error at t = 1 for y′ = −y against step sizes 0.5, 0.25, 0.125 and 0.0625. Euler's error falls by about half each time, an observed order of 1.04; RK4's error falls about sixteen-fold, an observed order of 4.08.

Explanation

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

6.1 The trapezoid rule and its error

Replace rectangles with sloped tops and the error drops by a factor of four every time you halve the step. Why four, and when does it overshoot?

The rule

Join neighbouring samples with straight lines and add the trapezoids: T = h·(y₀/2 + y₁ + y₂ + … + yₙ₋₁ + yₙ/2). End samples count half, inner samples fully. It is the average of the left and right sums.

Error and concavity

Error ≈ (b − a)·h²·f″/12. For a curve that bends upwards (f″ > 0, convex) the straight tops lie above it: the trapezoid overestimates. For a curve bending down it underestimates. For a straight line it is exact.

Choosing a sample rate

If you know roughly how sharply a signal bends (f″), the formula tells you the step needed for a target accuracy before you log anything. If you do not, integrate with h and with h/2: the difference is about three-quarters of the error of the coarser estimate, a check you can run on any data.

Derivation: Where the h² error comes from
  1. Take one strip of f(x) = x² on [0, h] (any smooth curve looks like a parabola up close).

  2. Trapezoid: h × (f(0) + f(h))/2 = h × (0 + h²)/2 = h³/2.

  3. Exact: ∫₀ʰ x² dx = h³/3. Error per strip: h³/2 − h³/3 = h³/6.

  4. For a general curve the per-strip error is about (h³/12)·f″; here f″ = 2, giving h³/6 as found.

  5. An interval of length L has n = L/h strips, so the total error ≈ (L/h)·(h³/12)·f″ = L·h²·f″/12.

  6. Halve h: the error falls to a quarter. Check: v = 0.5t² + 1 (f″ = 1) on [0, 4] with h = 1 gives 4 × 1 × 1/12 = 0.333 m; the trapezoid sum is 15 m against 14.667 m exact.

Common mix-ups

Open the Lite lesson: The trapezoid rule and its error

6.2 Local and global error, and the convergence study

Halve the step and RK4's error drops about sixteen times. How can you prove that from your own code, not from a textbook?

Question → method → evidence

Question: is my integrator correct, and is my step size small enough? Method: solve a problem with a known answer at h, h/2, h/4 (and smaller), measure the error at a fixed time, compute ratios. Evidence: ratios close to 2ᵖ confirm the order; a final error below your tolerance justifies the step.

When there is no exact answer

Use the finest run as a reference, or use differences between successive runs: E(h) ≈ |y_h − y_{h/2}|·2ᵖ/(2ᵖ − 1). Richardson extrapolation combines two runs, (2ᵖ y_{h/2} − y_h)/(2ᵖ − 1), to cancel the leading error term.

Limits of the study

Very small h eventually hits round-off error, which grows as steps multiply, so the error curve flattens or turns up. Very large h may be outside the asymptotic range or even unstable. Report the range of h where the ratio is steady, and plot error against h on log–log axes: the slope is the order.

Derivation: Evidence for RK4's fourth order
  1. Local error: if a method matches the exact Taylor series through the hᵖ term, one step from exact data is off by about C hᵖ⁺¹.

  2. Global error: reaching a fixed time T takes N = T/h steps. Roughly adding the local errors gives N·C hᵖ⁺¹ = C T hᵖ, so global order is p.

  3. Euler matches up to h¹ (p = 1). RK4 matches up to h⁴ (p = 4): its local error is O(h⁵), global O(h⁴).

  4. Test: with E(h) ≈ C hᵖ, E(h)/E(h/2) ≈ 2ᵖ, so p ≈ log₂(E(h)/E(h/2)).

  5. Evidence from this term's code (x″ = −x, x(0) = 1, error in x at t = 10): RK4 with 100, 200, 400 steps gives errors about 3.9×10⁻⁶, 2.6×10⁻⁷, 1.7×10⁻⁸. Ratios 14.9 and 15.5 give p ≈ 3.9 and 3.95, approaching 4.

  6. Explicit Euler on the same test gives 0.57, 0.24, 0.11: ratios 2.3 and 2.2, approaching 2¹ = 2 as h shrinks. The pre-asymptotic ratios are a reminder to test at small enough h.

Common mix-ups

Open the Lite lesson: Local and global error, and the convergence study

6.3 Stability regions and stiffness

The fast part of your model died out in a millisecond, yet your simulation still crawls along in microsecond steps. Why?

Stability regions

For a system x′ = Ax, each eigenvalue λ of A gives a test equation. An explicit method is stable only if hλ lies inside its stability region for every eigenvalue. So the fastest-decaying mode (largest |λ|) sets the maximum step, even if that mode is physically irrelevant after a moment.

What stiffness means

A problem is stiff when it has decaying modes on very different time scales, and you want to follow the slow one. Example: eigenvalues −1 and −1000. Accuracy for the slow mode would allow h ≈ 0.1, but explicit Euler stability needs h ≤ 0.002: fifty times more steps, purely to avoid blowing up.

The remedy

Implicit methods (backward Euler, the trapezoidal rule, BDF methods) solve an equation each step, often a linear system with (I − hA) via LU from week 2, but stay stable with large steps. Library solvers flagged for stiff problems (such as 'BDF' or 'Radau' options) do this automatically.

Derivation: Amplification factors and stability limits
  1. Test equation: y′ = λy, exact yₙ₊₁ = e^{hλ}yₙ. Let z = hλ.

  2. Explicit Euler: yₙ₊₁ = yₙ + hλyₙ = (1 + z)yₙ, so R(z) = 1 + z.

  3. Stable (no growth) iff |1 + z| ≤ 1. For real λ < 0: −2 ≤ z ≤ 0, so h ≤ 2/|λ|.

  4. RK4 on the test equation gives R(z) = 1 + z + z²/2 + z³/6 + z⁴/24 (the Taylor series of e^z to z⁴). On the negative real axis |R| ≤ 1 for z ≥ about −2.79.

  5. Implicit (backward) Euler: yₙ₊₁ = yₙ + hλyₙ₊₁, so R(z) = 1/(1 − z), with |R| < 1 for every z < 0: stable for any step on decaying problems.

Common mix-ups

Open the Lite lesson: Stability regions and stiffness

6.4 Convergence and sensitivity studies

Your simulated frequency is 1.0007 rad/s. Is the 7 from the physics, the step size or a parameter you guessed?

Convergence first

Run the simulation at several steps and compute the metric each time. Check that the differences shrink by about 2ᵖ per halving. Choose a step where the numerical error is at least ten times smaller than any effect you want to report. Record that choice and the evidence in the report.

Then sensitivity

Change one parameter at a time by a stated amount (for example ±10%) and record the change in each output: a one-at-a-time study. Report relative sensitivities (percentage change in output per percentage change in input). Compare with analytic derivatives where you have them, as in the derivation above.

Separating error sources

A result has numerical error (step size, round-off), parameter uncertainty (k_c known to ±10%) and model error (are springs really linear?). Convergence studies bound the first, sensitivity studies the second; only experiments address the third. Say clearly which you have quantified.

Derivation: Sensitivity of the frequencies to the coupling spring
  1. Equal masses m, outer springs k, coupling k_c: ω₁ = √(k/m), ω₂ = √((k + 2k_c)/m).

  2. ∂ω₁/∂k_c = 0: the in-phase mode never stretches the coupling spring.

  3. ∂ω₂/∂k_c = (1/2)(k + 2k_c)^{−1/2} · 2/√m = 1/(m ω₂).

  4. Relative sensitivity: (k_c/ω₂)(∂ω₂/∂k_c) = k_c/(m ω₂²) = k_c/(k + 2k_c), which is small when k_c ≪ k.

  5. Beat period T_b = 2π/(ω₂ − ω₁). For small k_c, ω₂ − ω₁ ≈ k_c/(m ω₁), so T_b ≈ 2π m ω₁ / k_c: a 10% change in k_c gives about a 10% change in T_b.

Common mix-ups

Open the Lite lesson: Convergence and sensitivity studies

Worked examples

The trapezoid rule and its error: example 1

Trapezoid rule for v = 0.5t² + 1 on [0, 4] with h = 1.

Solution

Samples 1, 1.5, 3, 5.5, 9. T = 1 × (0.5 + 1.5 + 3 + 5.5 + 4.5) = 15 m. Exact 14.667 m; error 0.333 m, matching (b − a)h²f″/12 = 4 × 1 × 1/12.

Local and global error, and the convergence study: example 1

Errors at t = 5 are 2.0×10⁻³ (h = 0.1) and 2.6×10⁻⁴ (h = 0.05). What is the observed order?

Solution

Ratio 2.0×10⁻³ / 2.6×10⁻⁴ ≈ 7.7; log₂ 7.7 ≈ 2.9. About third order (or a fourth-order method not yet in its asymptotic range: check with h = 0.025).

Stability regions and stiffness: example 1

x′ = Ax with eigenvalues −2 and −500. Largest stable explicit Euler step?

Solution

Need h ≤ 2/|λ| for both: 2/2 = 1 and 2/500 = 0.004. The binding one is h ≤ 0.004.

Convergence and sensitivity studies: example 1

m = 1 kg, k = 1 N/m, k_c = 0.1 N/m. Compute ω₁, ω₂ and T_b, then T_b with k_c = 0.11.

Solution

ω₁ = 1, ω₂ = √1.2 ≈ 1.0954, T_b = 2π/0.0954 ≈ 65.8 s. With k_c = 0.11: ω₂ = √1.22 ≈ 1.1045, T_b ≈ 2π/0.1045 ≈ 60.1 s: about 9% shorter for a 10% stiffer coupling, while ω₂ changed by only 0.8%.

Interactive figures, in words

Figure 6.2 from The trapezoid rule and its error

Choose the drone climb rate and the trapezoid rule. Step n through 1, 2, 4, 8, 16 and watch the error ratio in the readout settle near 4. Is the trapezoid estimate above or below the exact value? Look at the curve's shape to explain it.

With the trapezoid rule on the drone climb rate, the estimate is 15 m at n = 4 against an exact 14.667 m, and each doubling of n divides the error by about 4. The estimate is always slightly high because the curve bends upwards.

Figure 6.3 from Local and global error, and the convergence study

Read the convergence table below the energy plot. For each method, divide the h error by the h/2 error and the h/2 error by the h/4 error. Change h and see which ratios settle near 2 and which near 16.

Below the energy plot, a table lists for each method the error in x at t = 10 for steps h, h/2 and h/4, and the observed order computed from the last two. Changing h updates the table.

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. Predict the trapezoid error for the same integral with h = 0.5 s, in metres, using (b − a)h²f″/12 (f″ = 1).
    Answer it in “The trapezoid rule and its error”
  2. The trapezoid rule is applied to a curve that bends upwards (convex). The estimate is…
    Answer it in “The trapezoid rule and its error”
  3. E(h) = 0.032 and E(h/2) = 0.0021. What is the observed order p = log₂(E(h)/E(h/2))? (2 d.p.)
    Answer it in “Local and global error, and the convergence study”
  4. A method's local error is O(h³). Its global error is…
    Answer it in “Local and global error, and the convergence study”
  5. Your 'RK4' shows observed order 1.0 on a smooth test. Most likely?
    Answer it in “Local and global error, and the convergence study”
  6. Euler on y′ = −50y with h = 0.05. What is R = 1 + hλ?
    Answer it in “Stability regions and stiffness”
  7. Why can backward Euler take large steps on y′ = −1000y?
    Answer it in “Stability regions and stiffness”
  8. Which should you do first?
    Answer it in “Convergence and sensitivity studies”

Engineering applications

Trusting a simulator

Before a simulation result goes in a report, run it again at half the step. If the answer changes by more than the tolerance you care about, the first run was not converged.

Stiff circuits and chemistry

A circuit with a fast parasitic capacitor and a slow thermal mode forces an explicit method to tiny steps. Implicit methods take steps sized for the slow behaviour you actually want.

Watch (optional)

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

Summary

Glossary

Integral as accumulated area
An integral adds up a rate over time: the area under a rate graph gives the total accumulated amount. Field Guide
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
Floating-point rounding and comparison
Most decimal fractions cannot be stored exactly in binary floating point, so tiny rounding errors appear and == between floats is unreliable. Field Guide
Significant figures and rounding
Significant figures are the digits in a number that carry meaningful information, from the first non-zero digit to the last digit you are sure of. Round results so they do not claim more precision than the inputs. Field Guide

Project: A convergence study you could defend

Pick one School model (cooling, a falling object with drag or a mass on a spring). Simulate it with two methods at a sequence of step sizes, compute observed orders and choose the largest step that meets a stated tolerance.

Deliverables

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

References

← 5. Fourier and transform thinking7. Statistics for engineering evidence →