Textbooks/Applied Engineering Mathematics/Chapter 6Lite (plain text) version
6Numerical methods and their errors
Version 1 · Technically checked (automated checks only) · 4 source lessons · 8 practice items
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.
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.
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
Take one strip of f(x) = x² on [0, h] (any smooth curve looks like a parabola up close).
Trapezoid: h × (f(0) + f(h))/2 = h × (0 + h²)/2 = h³/2.
Exact: ∫₀ʰ x² dx = h³/3. Error per strip: h³/2 − h³/3 = h³/6.
For a general curve the per-strip error is about (h³/12)·f″; here f″ = 2, giving h³/6 as found.
An interval of length L has n = L/h strips, so the total error ≈ (L/h)·(h³/12)·f″ = L·h²·f″/12.
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
- The trapezoid rule is just a slightly better rectangle rule.
✓ It is a whole order better: error ∝ h², not h. - Error estimates need the exact answer.
✓ Comparing T_h and T_{h/2} estimates the error from the data alone.
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
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ᵖ⁺¹.
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.
Euler matches up to h¹ (p = 1). RK4 matches up to h⁴ (p = 4): its local error is O(h⁵), global O(h⁴).
Test: with E(h) ≈ C hᵖ, E(h)/E(h/2) ≈ 2ᵖ, so p ≈ log₂(E(h)/E(h/2)).
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.
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
- If two runs agree to three digits, the answer is accurate to three digits.
✓ Agreement shows convergence only if you are in the asymptotic range; check the ratio pattern across several halvings. - Smaller steps are always better.
✓ Round-off and cost grow; choose the largest step that meets your tolerance, with evidence.
Open the full 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
Test equation: y′ = λy, exact yₙ₊₁ = e^{hλ}yₙ. Let z = hλ.
Explicit Euler: yₙ₊₁ = yₙ + hλyₙ = (1 + z)yₙ, so R(z) = 1 + z.
Stable (no growth) iff |1 + z| ≤ 1. For real λ < 0: −2 ≤ z ≤ 0, so h ≤ 2/|λ|.
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.
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
- Instability means the physical system is unstable.
✓ Numerical instability can occur for a perfectly stable physical system if h is too large for the method. - Higher-order explicit methods cure stiffness.
✓ RK4's real stability limit is only about z ≥ −2.79; stiffness needs implicit methods.
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
Equal masses m, outer springs k, coupling k_c: ω₁ = √(k/m), ω₂ = √((k + 2k_c)/m).
∂ω₁/∂k_c = 0: the in-phase mode never stretches the coupling spring.
∂ω₂/∂k_c = (1/2)(k + 2k_c)^{−1/2} · 2/√m = 1/(m ω₂).
Relative sensitivity: (k_c/ω₂)(∂ω₂/∂k_c) = k_c/(m ω₂²) = k_c/(k + 2k_c), which is small when k_c ≪ k.
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
- A converged simulation is a validated one.
✓ Converged means the equations are solved accurately; validation asks whether they are the right equations. - Sensitivities can be read straight from the formula's exponents.
✓ Only for simple power laws; derived quantities like the beat period can be far more sensitive than the frequencies themselves.
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
Interactive figure (online). Description: 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.
Interactive figure (online). Description: 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.
Laboratory
Everything runs in your browser. No kit, nothing mains-powered. Simulations are simplified educational models.
Equation Lab exploration
Equation Lab: First-order systems
Step a decay equation with growing step sizes and find the step where the numerical solution starts to oscillate.
Open Equation Lab: First-order systems →Studio
Code Lab
Write Euler and RK4 for y′ = −y, halve the step four times and compute the observed order from your own error table.
Open Code Lab →
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.
- Predict the trapezoid error for the same integral with h = 0.5 s, in metres, using (b − a)h²f″/12 (f″ = 1). (m)
- The trapezoid rule is applied to a curve that bends upwards (convex). The estimate is…
- too high
- too low
- exact
- 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.)
- A method's local error is O(h³). Its global error is…
- O(h³)
- O(h²)
- O(h⁴)
- Your 'RK4' shows observed order 1.0 on a smooth test. Most likely?
- RK4 is first order
- A bug in the stages, e.g. a wrong time or state in k₂–k₄
- The step is too small
- Euler on y′ = −50y with h = 0.05. What is R = 1 + hλ?
- Why can backward Euler take large steps on y′ = −1000y?
- It is fourth order
- R(z) = 1/(1 − z) has |R| < 1 for all z < 0
- It skips the fast mode
- Which should you do first?
- Sensitivity study, then convergence
- Convergence study, then sensitivity
- Either: they measure the same thing
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 verified videos. Nothing loads from YouTube until you press play.
- Coding a Fourth-Order Runge-Kutta Integrator in Python and Matlab (Steve Brunton)
- Differential equations, a tourist's guide | DE1 (3Blue1Brown)
Chapter summary
- A method of order p has global error roughly proportional to h^p.
- Observed order = log2(E(h) / E(h/2)); if it does not match theory, suspect a bug.
- Explicit methods have stability limits; on stiff problems they force tiny steps.
- A convergence study (shrink the step until the answer stops changing) comes before any sensitivity study.
Glossary
- Integral as accumulated area
- An integral adds up a rate over time: the area under a rate graph gives the total accumulated amount.
- 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/τ).
- 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.
- 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.
Definitions from the 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
- The model and the quantity of interest
- An error table and log-log plot for both methods
- The chosen step with its justification
Keep your work in your Engineering Journal; it stays private unless you choose to share it.
References
- William H. Press et al. (2007). Numerical Recipes: The Art of Scientific Computing, 3rd edition. Cambridge University Press.
- Erwin Kreyszig (2011). Advanced Engineering Mathematics, 10th edition. Wiley.
- William E. Boyce and Richard C. DiPrima (2012). Elementary Differential Equations and Boundary Value Problems, 10th edition. Wiley.
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.