Numerical Approximation and Error

Sources of numerical error: truncation, floating-point roundoff, stability, and convergence in computation.

What it is

Numerical approximation is the physical and mathematical foundation that models, bounds, and manages the unavoidable discrepancies arising when continuous physical laws formulated over R\mathbb{R} are evaluated on finite-precision computing architectures.

The total computational error splits into three irreducible sources:

  1. Truncation error (EtruncE_{\text{trunc}}): Arises from replacing continuous infinite operators (infinite Taylor series, derivatives as limits lim⁡h→0\lim_{h \to 0}, or Riemann integrals) with finite discrete approximations parameterized by mesh step hh. Its asymptotic decay follows Landau notation O(hp)\mathcal{O}(h^p), where pp is the convergence order.
  2. Roundoff error (EroundE_{\text{round}}): Stemming from representing real continuum numbers using fixed binary formats under IEEE-754 standard (single precision Float32 with 24-bit significand and machine epsilon ϵmach≈1.19×10−7\epsilon_{\text{mach}} \approx 1.19 \times 10^{-7}; or double precision Float64 with 53-bit significand and ϵmach≈2.22×10−16\epsilon_{\text{mach}} \approx 2.22 \times 10^{-16}). Every arithmetic operation incurs relative roundoff bounded by ϵmach\epsilon_{\text{mach}}.
  3. Catastrophic cancellation: A pathological loss of precision occurring when subtracting two nearly equal floating-point numbers: identical leading significant digits cancel, leaving only prior roundoff noise in the remaining bits.

Why it appears in physics

In modern computational physics (astrophysics, quantum many-body systems, climate modeling, fusion plasma physics), nonlinear differential systems lack closed-form analytical solutions:

  • Simulating NN-body celestial orbits, turbulence, or tokamak magnetic confinement demands spatial and temporal discretization.
  • A fundamental tension exists known as the step-size trade-off: reducing step size hh drives truncation error down as C1hpC_1 h^p, but arithmetic operation count scales as 1/h1/h, compounding floating-point roundoff error as C2ϵmach/hqC_2 \epsilon_{\text{mach}} / h^q. Below an optimal step h∗h^*, shrinking hh exacerbates total numerical error.
  • Neglecting numerical stability and matrix condition numbers leads to unphysical simulations characterized by energy divergence, violated conservation laws, or artificial numerical blowup.

Visual or geometric idea

In a log-log plot (log⁡E\log E vs log⁡h\log h), total error forms a characteristic "V"-shaped profile:

  • At large hh, truncation error dominates along a line with positive slope +p+p: log⁡E≈plog⁡h+const\log E \approx p \log h + \text{const}.
  • At tiny hh, floating-point cancellation and roundoff compound, creating a branch with negative slope.
  • The global minimum marks the optimal step size h∗h^*. Stepping below h∗h^* consumes CPU cycles while degrading numerical accuracy.

Minimal symbolic language

  1. Absolute and relative error: Eabs=∣xtrue−xapprox∣,Erel=∣xtrue−xapprox∣∣xtrue∣E_{\text{abs}} = |x_{\text{true}} - x_{\text{approx}}|, \qquad E_{\text{rel}} = \frac{|x_{\text{true}} - x_{\text{approx}}|}{|x_{\text{true}}|}
  2. IEEE-754 standard floating-point model: fl⁡(x)=x(1+δ),∣δ∣≤ϵmach\operatorname{fl}(x) = x (1 + \delta), \qquad |\delta| \leq \epsilon_{\text{mach}}
  3. Catastrophic cancellation (x≈yx \approx y): fl⁡(x−y)=(x−y)+xδ1−yδ2=(x−y)[1+xδ1−yδ2x−y]\operatorname{fl}(x - y) = (x - y) + x \delta_1 - y \delta_2 = (x - y) \left[ 1 + \frac{x \delta_1 - y \delta_2}{x - y} \right] As (x−y)→0(x - y) \to 0, relative error diverges unless expressions are reformulated algebraically.
  4. Condition number of problem f(x)f(x): κ(x)=∣xf′(x)f(x)∣\kappa(x) = \left| \frac{x f'(x)}{f(x)} \right| If κ(x)≫1\kappa(x) \gg 1, the physical problem is ill-conditioned (hypersensitive to perturbations).

What the result means

Understanding numerical error elevates scientific simulations from ad-hoc coding into verifiable science:

  • A computational calculation possesses no scientific validity without an accompanying convergence proof or quantified error bound.
  • In orbital or molecular dynamics, confirming that global error drops at the theoretical rate (h2,h4h^2, h^4) validates both software implementation and numerical stability.

When not to use it

  1. Do not blindly decrease hh past the roundoff threshold: In numerical finite-difference differentiation, selecting h=10−16h = 10^{-16} in Float64 yields zero or random noise due to catastrophic cancellation.
  2. Do not use single precision (Float32) for long-duration dynamic trajectories: Roundoff drift accumulated over millions of integration steps destroys energy conservation in physical orbits.
  3. Do not conflate numerical error with physics model error: Numerical error quantifies the gap between algorithm and differential equation; it cannot detect missing friction or neglected quantum corrections in the original physics formulation.

Operational summary

  • Write the continuous differential or integral equation and choose an approximation scheme.
  • Identify the asymptotic truncation order O(hp)\mathcal{O}(h^p).
  • Inspect formulas for catastrophic cancellation hazards (differences of close numbers, square root subtractions); eliminate them via algebraic conjugates or local Taylor series.
  • Choose step size hh balancing truncation against IEEE-754 machine epsilon limits.
  • Perform a systematic grid refinement test (h,h/2,h/4h, h/2, h/4) to experimentally confirm expected convergence orders.

Procedure for Numerical Error Control and Mitigation

Before calculating

Before executing computational physical simulations:

  • Identify runtime floating-point precision (Float32: ϵmach≈1.2×10−7\epsilon_{\text{mach}} \approx 1.2 \times 10^{-7}, 7 decimal digits; Float64: ϵmach≈2.2×10−16\epsilon_{\text{mach}} \approx 2.2 \times 10^{-16}, 16 decimal digits).
  • Scan mathematical formulas for catastrophic cancellation vulnerabilities (e.g. 1−cos⁡(x)1 - \cos(x) for x→0x \to 0, or x+1−x\sqrt{x + 1} - \sqrt{x} for x≫1x \gg 1).

Step 1: identify the mathematical object

Classify the numerical algorithm and its truncation profile:

  • Finite-difference derivative: Truncation O(h)\mathcal{O}(h) for forward/backward or O(h2)\mathcal{O}(h^2) for centered differences.
  • Numerical quadrature: Truncation O(h2)\mathcal{O}(h^2) for trapezoidal or O(h4)\mathcal{O}(h^4) for Simpson's rule.
  • ODE solver (Runge-Kutta): Local truncation error O(hp+1)\mathcal{O}(h^{p+1}), global error O(hp)\mathcal{O}(h^p).

Step 2: choose the operation (Cancellation elimination)

If nearly equal values are subtracted, algebraically reformulate before coding:

  • Root subtraction: a−b=a−ba+b\sqrt{a} - \sqrt{b} = \frac{a - b}{\sqrt{a} + \sqrt{b}} (multiplying by conjugate removes cancellation).
  • Small-angle trigonometry: 1−cos⁡(x)=2sin⁡2(x/2)1 - \cos(x) = 2 \sin^2(x/2) or Taylor expansion x22−x424+…\frac{x^2}{2} - \frac{x^4}{24} + \dots.
  • Quadratic formula with b2≫4acb^2 \gg 4 a c: x1=−b−sgn⁡(b)b2−4ac2a,x2=cax1x_1 = \frac{-b - \operatorname{sgn}(b)\sqrt{b^2 - 4ac}}{2a}, \qquad x_2 = \frac{c}{a x_1}

Step 3: preserve units and signs

  • Absolute error EabsE_{\text{abs}} preserves identical dimensions of the physical observable.
  • Relative error ErelE_{\text{rel}} and machine epsilon ϵmach\epsilon_{\text{mach}} are dimensionless pure numbers.
  • In numerical differentiation f′(x)≈f(x+h)−f(x−h)2hf'(x) \approx \frac{f(x+h) - f(x-h)}{2h}, step size hh must carry identical physical units as input variable xx.

Step 4: calculate (Optimal step-size calculation h∗h^*)

For a numerical method with truncation error αhp\alpha h^p and roundoff growth ϵmachhq\frac{\epsilon_{\text{mach}}}{h^q}:

  1. Formulate total error: Etotal(h)=αhp+βϵmachhqE_{\text{total}}(h) = \alpha h^p + \beta \frac{\epsilon_{\text{mach}}}{h^q}
  2. Set derivative to zero: dEtotaldh=pαhp−1−qβϵmachhq+1=0\frac{d E_{\text{total}}}{dh} = p \alpha h^{p-1} - q \beta \frac{\epsilon_{\text{mach}}}{h^{q+1}} = 0
  3. Solve for optimal step size: h∗=(qβϵmachpα)1p+qh^* = \left( \frac{q \beta \epsilon_{\text{mach}}}{p \alpha} \right)^{\frac{1}{p + q}} (For centered differences with p=2,q=1p=2, q=1: h∗∼ϵmach1/3h^* \sim \epsilon_{\text{mach}}^{1/3}. In Float64, h∗∼(10−16)1/3≈10−5−10−6h^* \sim (10^{-16})^{1/3} \approx 10^{-5} - 10^{-6}).

Step 5: interpret the result (Richardson convergence check)

Compute approximations across three halved step sizes (h,h/2,h/4h, h/2, h/4) denoted A1,A2,A3A_1, A_2, A_3:

  1. Calculate convergence ratio: R=A1−A2A2−A3≈2pR = \frac{A_1 - A_2}{A_2 - A_3} \approx 2^p
  2. If R≈2pR \approx 2^p (e.g. R≈4R \approx 4 for 2nd-order p=2p=2, or R≈16R \approx 16 for 4th-order p=4p=4), the computation resides cleanly in the asymptotic convergence regime free from roundoff contamination.
  3. Richardson extrapolation for leading error cancellation: Arefined=A3+A3−A22p−1A_{\text{refined}} = A_3 + \frac{A_3 - A_2}{2^p - 1}

Self-check checklist

  • Is selected step hh larger than the roundoff minimum h∗h^*?
  • Did I eliminate catastrophic cancellations via conjugate or series expansions?
  • Does empirical convergence ratio RR match theoretical 2p2^p?
  • Did I enforce Float64 precision for long dynamic runs?
  • Are physical conservation invariants (energy, momentum) preserved within discretization bounds?

Guided Example: Catastrophic Cancellation in Relativistic Kinematics

Physical Situation

A subatomic particle of rest mass m=1.000 GeV/c2m = 1.000 \text{ GeV}/c^2 is accelerated inside the Large Hadron Collider (LHC) to total relativistic energy E=1000.000000000100 GeVE = 1000.000000000100 \text{ GeV}. We compute relativistic momentum pp using Einstein's energy-momentum relation: E2=p2c2+m2c4  ⟹  pc=E2−m2c4E^2 = p^2 c^2 + m^2 c^4 \implies p c = \sqrt{E^2 - m^2 c^4} In natural units (c=1c=1), p=E2−m2p = \sqrt{E^2 - m^2}. Because E≫mE \gg m, momentum pp is nearly indistinguishable from EE. If kinetic energy and velocity deficit Δv=c−v=1−pE=1−1−m2E2\Delta v = c - v = 1 - \frac{p}{E} = 1 - \sqrt{1 - \frac{m^2}{E^2}} are computed naively in floating-point software, catastrophic cancellation destroys precision.

Mathematical Translation

Evaluating with E=104 GeVE = 10^4 \text{ GeV} and m=1 GeVm = 1 \text{ GeV}: γ=Em=104,m2E2=10−8\gamma = \frac{E}{m} = 10^4, \qquad \frac{m^2}{E^2} = 10^{-8} The naive subtraction evaluates: 1−1−10−81 - \sqrt{1 - 10^{-8}} In floating-point math, 1−10−8=0.9999999950000000…\sqrt{1 - 10^{-8}} = 0.9999999950000000\dots Subtracting 1−0.999999995…1 - 0.999999995\dots cancels the leading 8 identical digits, destroying half the mantissa in Float64 and producing total cancellation to 0.00.0 in Float32.

Step-by-Step Calculation

  1. Conjugate Algebraic Reformulation: Δv=1−1−m2E2=(1−1−m2E2)(1+1−m2E2)1+1−m2E2=m2/E21+1−m2E2\Delta v = 1 - \sqrt{1 - \frac{m^2}{E^2}} = \frac{\left(1 - \sqrt{1 - \frac{m^2}{E^2}}\right)\left(1 + \sqrt{1 - \frac{m^2}{E^2}}\right)}{1 + \sqrt{1 - \frac{m^2}{E^2}}} = \frac{m^2 / E^2}{1 + \sqrt{1 - \frac{m^2}{E^2}}}
  2. Stable Floating-Point Evaluation: The denominator is now a stable sum of positive quantities: 1+1−10−8≈1+0.999999995=1.9999999951 + \sqrt{1 - 10^{-8}} \approx 1 + 0.999999995 = 1.999999995 The numerator is: m2E2=10−8\frac{m^2}{E^2} = 10^{-8} Therefore: Δv=10−81.999999995≈5.0000000125×10−9 (in units of c)\Delta v = \frac{10^{-8}}{1.999999995} \approx 5.0000000125 \times 10^{-9} \text{ (in units of } c)
  3. Binomial Taylor Alternative: 1−1−ϵ=12ϵ+18ϵ2+⋯=12(10−8)+18(10−16)=5.0000000000000125×10−91 - \sqrt{1 - \epsilon} = \frac{1}{2}\epsilon + \frac{1}{8}\epsilon^2 + \dots = \frac{1}{2}(10^{-8}) + \frac{1}{8}(10^{-16}) = 5.0000000000000125 \times 10^{-9}

Reading the Result

The conjugate reformulation preserves all 16 significant decimal figures in Float64. The particle travels just Δv≈5.0×10−9c≈1.5 m/s\Delta v \approx 5.0 \times 10^{-9} c \approx 1.5 \text{ m/s} below the speed of light. Naive evaluation would have returned zero or suffered 50%50\% rounding error.

Common Error Avoided

Directly evaluating differences of square roots of nearly identical quantities. Rationalizing with algebraic conjugates eradicates catastrophic cancellation at zero additional computational cost.


Inverse Example: Identifying the Optimal Step Size in Numerical Differentiation

Physical Situation

A spacecraft flight computer estimates acceleration a(t)=v′(t)a(t) = v'(t) from velocity telemetry v(t)=sin⁡(t)v(t) = \sin(t) at t=1.0 st = 1.0 \text{ s} using central differences on a standard 64-bit IEEE 754 platform (ϵmach≈2.22×10−16\epsilon_{\text{mach}} \approx 2.22 \times 10^{-16}). The exact analytical derivative is v′(1.0)=cos⁡(1.0)≈0.5403023058681398v'(1.0) = \cos(1.0) \approx 0.5403023058681398.

Given Result

Central difference formula: v′(t)≈v(t+h)−v(t−h)2hv'(t) \approx \frac{v(t + h) - v(t - h)}{2h} Testing three step sizes:

  • h=10−2h = 10^{-2}: Absolute error ϵ=9.0×10−6\epsilon = 9.0 \times 10^{-6} (dominated by O(h2)\mathcal{O}(h^2) truncation).
  • h=10−5h = 10^{-5}: Absolute error ϵ=4.2×10−12\epsilon = 4.2 \times 10^{-12} (optimal balance).
  • h=10−14h = 10^{-14}: Absolute error ϵ=0.08\epsilon = 0.08 (dominated by ϵmach/h\epsilon_{\text{mach}} / h floating-point cancellation).

Analytical Reconstruction

Total numerical error balances truncation and roundoff: E(h)=Mh26+ϵmachhE(h) = \frac{M h^2}{6} + \frac{\epsilon_{\text{mach}}}{h} Minimizing E′(h)=Mh3−ϵmachh2=0E'(h) = \frac{M h}{3} - \frac{\epsilon_{\text{mach}}}{h^2} = 0: hopt=(3ϵmachM)1/3∼ϵmach1/3≈(10−16)1/3≈10−5.3h_{\text{opt}} = \left( \frac{3 \epsilon_{\text{mach}}}{M} \right)^{1/3} \sim \epsilon_{\text{mach}}^{1/3} \approx (10^{-16})^{1/3} \approx 10^{-5.3}

What Physical Question It Can Answer

Why does making the numerical step arbitrarily small (h→0h \to 0) destroy the calculated derivative? Because dividing rounding noise by an infinitesimal hh amplifies machine noise into macroscopic errors, as proved by the h=10−14h = 10^{-14} calculation.

Boundary Verification

As h→0h \to 0, E(h)→∞E(h) \to \infty; as h→1h \to 1, E(h)∼h2→O(1)E(h) \sim h^2 \to \mathcal{O}(1). The minimum lies strictly at hopt∼ϵmach1/3h_{\text{opt}} \sim \epsilon_{\text{mach}}^{1/3}.

Common Mistakes in Numerical Approximation and Error

1. Shrinking step size hh assuming error monotonically vanishes

It seems reasonable because elementary calculus defines derivatives and integrals as the limit h→0h \to 0. It fails because on real finite-precision machines (IEEE-754), total computational error traces a "V"-shape: as hh decreases, truncation shrinks but roundoff error compounds as ϵmach/hq\epsilon_{\text{mach}} / h^q. Below optimal step h∗h^*, smaller steps amplify global error. It is detected when empirical error stops decreasing and begins oscillating or rising steeply. It is corrected by determining optimal step size h∗∼ϵmach1/(p+q)h^* \sim \epsilon_{\text{mach}}^{1/(p+q)} and running grid convergence checks. Mini-example: evaluating f′(x)≈f(x+h)−f(x)hf'(x) \approx \frac{f(x+h) - f(x)}{h} with h=10−16h = 10^{-16} in Float64 yields 0.00.0 instead of the true slope, because f(x+10−16)f(x+10^{-16}) rounds back to f(x)f(x).

2. Subtracting nearly equal floating-point numbers (catastrophic cancellation)

It seems reasonable because computers are deterministic machines providing 16 decimal digits of precision. It fails because if two floats match in their first 14 decimal digits, subtracting them cancels those 14 digits, leaving only 2 digits of genuine precision followed by roundoff noise. It is detected when sudden accuracy loss occurs in root differences, small-angle trigonometry, or quadratic formulas. It is corrected by algebraically reformulating expressions via conjugates, Taylor expansions, or half-angle identities. Mini-example: in Float32, evaluating 1−cos⁡(10−4)1 - \cos(10^{-4}) outputs 0.00.0; computing 2sin⁡2(10−4/2)2 \sin^2(10^{-4}/2) yields accurate 5.000000×10−95.000000 \times 10^{-9}.

3. Testing floating-point equality with exact comparisons

It seems reasonable because mathematically equivalent expressions should evaluate identically. It fails because binary floating-point arithmetic is neither associative nor distributive: (0.1+0.2)+0.3≠0.1+(0.2+0.3)(0.1 + 0.2) + 0.3 \neq 0.1 + (0.2 + 0.3) under IEEE-754. Evaluating 0.1 + 0.2 == 0.3 returns false in most programming languages. It is detected when iterative convergence loops hang in infinite cycles. It is corrected by using absolute and relative error bounds: abs(x - y) <= atol + rtol * abs(y). Mini-example: an iteration while x != 1.0 with x += 0.1 never terminates because x never hits binary 1.0000000000000000.

4. Confusing numerical stability with approximation order

It seems reasonable because higher-order solvers (like RK4) are more accurate than low-order schemes (like Euler). It fails because an algorithm can possess high asymptotic accuracy while being unstable for stiff problems or if step size exceeds the algorithm's stability boundary. It is detected when numerical traces explode abruptly to ±∞\pm \infty after behaving normally in initial steps. It is corrected by inspecting the linear stability domain z=λΔtz = \lambda \Delta t in the complex plane and adopting implicit schemes (Crank-Nicolson, Radau) for stiff equations. Mini-example: in chemical kinetics with rate constants k1=1,k2=106k_1 = 1, k_2 = 10^6, explicit RK4 requires Δt<10−6\Delta t < 10^{-6} not for accuracy, but to prevent explosive numerical blowup.

5. Summing series in descending order of magnitude

It seems reasonable because adding dominant large terms first feels like capturing the bulk of the result. It fails because adding a tiny term to a massive accumulator shifts the small term's bits off the significand, causing complete numerical absorption. It is detected when summing N=107N = 10^7 small positive floats causes the accumulator to stall and stop growing. It is corrected by sorting terms in ascending order (smallest to largest) or implementing Kahan compensated summation. Mini-example: in Float32, adding 1.01.0 to an accumulator of 10810^8 has zero effect: 108+1.0=10810^8 + 1.0 = 10^8. Adding 1.01.0 one million times in a loop still leaves the accumulator at 10810^8.

Quick detection rule

  • Subtracting two values? Check if ∣x/y∣∈[0.99,1.01]|x/y| \in [0.99, 1.01]. If so, catastrophic cancellation is occurring.
  • Reducing step size hh? Plot error on a log-log axis. If the line turns upward, you have breached the roundoff floor.

Physical Applications of Numerical Approximation and Error

1. Astrodynamics: interplanetary trajectory calculations and orbital semimajor axes

Appears in aerospace engineering when integrating equations of motion for deep-space probes (Voyager, New Horizons) under the gravitational influence of the Sun and Solar System planets. It is calculated by integrating the NN-body differential equations r¨=−∑GMir−ri∣r−ri∣3\ddot{\mathbf{r}} = -\sum G M_i \frac{\mathbf{r} - \mathbf{r}_i}{|\mathbf{r} - \mathbf{r}_i|^3} over multi-decade mission horizons. The result provides probe state vectors for gravity-assist flybys with trajectory error bounds within tens of kilometers after traversing billions of kilometers. The critical danger is accumulated roundoff and artificial energy dissipation caused by non-conservative integrators (standard RK4); over a 30-year mission with hourly steps, tiny 10−1510^{-15} roundoff per step compounds into noticeable orbital energy drift. As a final sanity check, high-order symplectic integrators (Gauss-Radau, Yoshida) are deployed and strict invariance of the Laplace-Runge-Lenz vector and total Hamiltonian energy is enforced.

2. Computational quantum mechanics: stationary Schrödinger eigenvalue problems

Appears in atomic and solid-state physics when solving for energy eigenstates and wavefunctions ψ(x)\psi(x) in non-harmonic potentials or diatomic molecules via the shooting method or spatial finite differences: −ℏ22md2ψdx2+V(x)ψ=Eψ-\frac{\hbar^2}{2m} \frac{d^2\psi}{dx^2} + V(x)\psi = E\psi. It is calculated using the sixth-order Numerov algorithm O(h6)\mathcal{O}(h^6) for second-order differential equations lacking first derivatives. The result determines discrete bound-state energies EnE_n and quantum barrier tunneling probabilities in semiconductor heterostructures. The critical danger is using too coarse a spatial grid hh in classically forbidden regions where wavefunctions decay exponentially; if truncation error fails to resolve exponential curvature, the numerical solution blows up toward ±∞\pm \infty, preventing eigenvalue convergence. As a final sanity check, wavefunction orthonormality ∫∣ψn∣2dx=1\int |\psi_n|^2 dx = 1 is verified and numerical eigenvalues are benchmarked against first-order perturbation theory.

3. Geophysical fluid dynamics: numerical weather prediction and climate models

Appears in atmospheric physics when solving continuous hydrodynamic Navier-Stokes primitive equations across three-dimensional global atmospheric grids. It is calculated by discretizing pressure gradient and wind advection terms via centered finite differences or spherical harmonic spectral transforms. The result predicts the temporal evolution of storm tracks, thermal fronts, and cyclonic systems across multi-day forecast windows. The critical danger is violating the Courant-Friedrichs-Lewy condition (CFL: C=uΔtΔx≤1C = \frac{u \Delta t}{\Delta x} \leq 1); if wind or acoustic/gravity wave speeds exceed one grid cell per time step, truncation errors amplify exponentially, triggering explosive unphysical numerical blowup. As a final sanity check, adaptive time-stepping tracks local CFL numbers and hyperdiffusion operators selectively damp sub-grid eddies without altering planetary Rossby wave dynamics.

4. Plasma physics and fusion: charged particle orbit tracking in Tokamak reactors

Appears in magnetic confinement fusion (ITER) when calculating guiding-center and full-orbit trajectories of thermal deuterons and fast fusion alpha particles trapped in helical toroidal fields. It is calculated by integrating the Lorentz force F=q(E+v×B)\mathbf{F} = q (\mathbf{E} + \mathbf{v} \times \mathbf{B}) via the Boris kinematic algorithm. The result resolves gyromotion Larmor radii and predicts whether trapped banana orbits drift into divertor or first-wall armor tiles (confinement loss). The critical danger is employing standard Runge-Kutta solvers for the rotational term v×B\mathbf{v} \times \mathbf{B}; standard solvers fail to conserve magnetic moment μ=mv⊥2/(2B)\mu = m v_\perp^2 / (2B) and gyro-radius, causing particles to gain artificial numerical kinetic energy and escape confinement. As a final sanity check, Boris integration exactly preserves velocity magnitude in pure magnetic fields (∣vn+1∣=∣vn∣|\mathbf{v}_{n+1}| = |\mathbf{v}_n|), guaranteeing strict kinetic energy conservation across millions of gyro-periods.

5. Electromagnetic optics: FDTD modeling of photonic metamaterials and waveguides

Appears in photonics and optical communications when simulating laser pulse propagation across dielectric waveguides and photonic bandgap crystals via Yee-grid Finite-Difference Time-Domain (FDTD). It is calculated by interleaving spatial and temporal components of electric E\mathbf{E} and magnetic H\mathbf{H} fields on staggered cubic grids shifted by half steps in space and time. The result provides spectral transmission curves, dispersion relations, and chromatic group velocity dispersion in specialty optical fibers. The critical danger is numerical dispersion: on discrete grids, the phase velocity of simulated electromagnetic waves vnumv_{\text{num}} does not equal cc identically, but varies artificially with propagation angle and wavelength-to-grid ratio λ/Δx\lambda / \Delta x. On coarse grids, ultra-short pulses artificially broaden and distort due to spatial discretization truncation. As a final sanity check, spatial grid resolution is constrained to at least 20 cells per dielectric wavelength (Δx≤λmin/(20nref)\Delta x \leq \lambda_{\text{min}} / (20 n_{\text{ref}})) and Courant numbers are locked to the multidimensional stability optimum.

Guided Practice: Numerical Approximation and Error

Level 1: recognition

Classify the dominant numerical error in each computational operation (truncation, roundoff, or catastrophic cancellation):

  1. Computing π\pi by summing the first 100 terms of the Gregory-Leibniz alternating series ∑k=099(−1)k2k+1\sum_{k=0}^{99} \frac{(-1)^k}{2k+1}.
  2. Evaluating y=1000001−1000y = \sqrt{1000001} - 1000 on a standard computer.
  3. Storing f(x)=13xf(x) = \frac{1}{3} x as Float32 in memory.
  4. Integrating a Newtonian planetary orbit over 10 million cycles observing secular energy drift.

Solution:

  1. Truncation error (terminating an infinite series after finite operations).
  2. Catastrophic cancellation (subtracting two nearly identical large floating-point numbers).
  3. Roundoff error (the fraction 1/31/3 is an infinite binary recurring float 0.010101…20.010101\dots_2 truncated to 24 significand bits).
  4. Accumulated roundoff drift (random-walk and systematic accumulation over millions of floating-point operations).

Level 2: direct application

Approximate the first derivative of f(x)=exf(x) = e^x at x=0x=0 via forward finite differences: D+(h)=eh−1hD_+(h) = \frac{e^h - 1}{h} Exact theoretical derivative is f′(0)=e0=1f'(0) = e^0 = 1. Derive the analytical truncation error via Taylor expansion of ehe^h and compute numerical error for h=0.1h = 0.1 and h=0.01h = 0.01.

Solution:

  1. Taylor series: eh=1+h+h22+h36+O(h4)e^h = 1 + h + \frac{h^2}{2} + \frac{h^3}{6} + \mathcal{O}(h^4)
  2. Substitute into operator: D+(h)=(1+h+h22+… )−1h=1+h2+O(h2)D_+(h) = \frac{(1 + h + \frac{h^2}{2} + \dots) - 1}{h} = 1 + \frac{h}{2} + \mathcal{O}(h^2)
  3. Truncation error: Etrunc=∣D+(h)−1∣=h2+O(h2)E_{\text{trunc}} = |D_+(h) - 1| = \frac{h}{2} + \mathcal{O}(h^2) First-order accuracy O(h)\mathcal{O}(h).
  4. Numerical evaluation:
    • For h=0.1h = 0.1: Etrunc≈0.1/2=0.05E_{\text{trunc}} \approx 0.1 / 2 = 0.05 (5%5\% error; computed value 1.051711.05171).
    • For h=0.01h = 0.01: Etrunc≈0.01/2=0.005E_{\text{trunc}} \approx 0.01 / 2 = 0.005 (0.5%0.5\% error; computed value 1.0050171.005017). Decimating step size by 10 cuts error by exactly 10 (linear convergence).

Level 3: tool selection

In astrophysical software, you must evaluate gravitational potential energy differences between close orbital points (r2=r1+δr_2 = r_1 + \delta with δ≪r1\delta \ll r_1): ΔU=−GMm(1r2−1r1)\Delta U = -G M m \left( \frac{1}{r_2} - \frac{1}{r_1} \right) How should this expression be rewritten to guarantee numerical stability free from cancellation?

Solution: Evaluating 1r2−1r1\frac{1}{r_2} - \frac{1}{r_1} directly causes catastrophic floating-point cancellation. Algebraically combine fractions before computing: 1r2−1r1=r1−r2r1r2=−δr1(r1+δ)\frac{1}{r_2} - \frac{1}{r_1} = \frac{r_1 - r_2}{r_1 r_2} = \frac{-\delta}{r_1 (r_1 + \delta)} Substituting back: ΔU=GMmδr1(r1+δ)\Delta U = \frac{G M m \delta}{r_1 (r_1 + \delta)} This expression uses only products and additions of positive numbers, eliminating subtraction of close numbers and retaining all 16 Float64 digits, even when δ=10−12r1\delta = 10^{-12} r_1.

Level 4: physical interpretation

A computational physicist simulates a simple harmonic oscillator mx¨+kx=0m \ddot{x} + k x = 0 via explicit Euler stepping (xn+1=xn+vnΔtx_{n+1} = x_n + v_n \Delta t; vn+1=vn−ω2xnΔtv_{n+1} = v_n - \omega^2 x_n \Delta t). Over 1000 cycles, the oscillation amplitude diverges exponentially and mechanical energy grows by a factor of 10. Explain why this behavior is not floating-point roundoff but algorithmic numerical instability.

Solution: Compute the state transition matrix for explicit Euler: (xn+1vn+1)=(1Δt−ω2Δt1)(xnvn)\begin{pmatrix} x_{n+1} \\ v_{n+1} \end{pmatrix} = \begin{pmatrix} 1 & \Delta t \\ -\omega^2 \Delta t & 1 \end{pmatrix} \begin{pmatrix} x_n \\ v_n \end{pmatrix} Matrix determinant is: det⁡(A)=1⋅1−(Δt)(−ω2Δt)=1+ω2Δt2\det(A) = 1 \cdot 1 - (\Delta t)(-\omega^2 \Delta t) = 1 + \omega^2 \Delta t^2 The determinant represents the phase-space volume expansion per step. Because det⁡(A)=1+ω2Δt2>1\det(A) = 1 + \omega^2 \Delta t^2 > 1 for any finite Δt>0\Delta t > 0, eigenvalues have magnitude strictly greater than 1: ∣λ∣=1+ω2Δt2>1|\lambda| = \sqrt{1 + \omega^2 \Delta t^2} > 1. Physical interpretation: Explicit Euler injects artificial numerical energy at every step. This is an algorithmic instability, not roundoff. Conservative physical systems require symplectic integrators (Symplectic Euler, Verlet) where det⁡(A)≡1\det(A) \equiv 1.

Level 5: intentional mistake

To solve ax2+bx+c=0a x^2 + b x + c = 0 with a=1a = 1, b=108b = 10^8, c=1c = 1, a student codes the standard textbook formula: x1=−b+b2−4ac2a,x2=−b−b2−4ac2ax_1 = \frac{-b + \sqrt{b^2 - 4ac}}{2a}, \qquad x_2 = \frac{-b - \sqrt{b^2 - 4ac}}{2a} The code outputs x1=0.0x_1 = 0.0 and x2=−108x_2 = -10^8. Prove that x1=0x_1 = 0 is completely wrong and determine the correct root using a stabilized algorithm.

Conceptual blunder: Because b=108b = 10^8, b2=1016b^2 = 10^{16}. In Float64 arithmetic, subtracting 4ac=44 a c = 4 from 101610^{16} falls beyond the 53-bit significand, so b2−4ac\sqrt{b^2 - 4ac} evaluates to 10810^8 identically. Evaluating x1=−108+1082=0.0x_1 = \frac{-10^8 + 10^8}{2} = 0.0 destroys the smaller root via catastrophic cancellation. However, Vieta's theorem requires x1⋅x2=c/a=1x_1 \cdot x_2 = c/a = 1. Since x2≈−108x_2 \approx -10^8, the true root is x1=1/x2=−10−8≠0x_1 = 1 / x_2 = -10^{-8} \neq 0.

Stabilized calculation: Compute the non-cancelling root first: x2=−b−sgn⁡(b)b2−4ac2a=−1.0×108x_2 = \frac{-b - \operatorname{sgn}(b)\sqrt{b^2 - 4ac}}{2a} = -1.0 \times 10^8 Obtain the complementary root via Vieta's formula: x1=cax2=11⋅(−108)=−1.0×10−8x_1 = \frac{c}{a x_2} = \frac{1}{1 \cdot (-10^8)} = -1.0 \times 10^{-8} Plugging x1=−10−8x_1 = -10^{-8} back confirms accuracy: (−10−8)2+108(−10−8)+1=10−16≈0(-10^{-8})^2 + 10^8(-10^{-8}) + 1 = 10^{-16} \approx 0. The textbook formula produced a 100%100\% relative error.