Skip to content

Truncation Error

Every numerical derivative is an approximation. The gap between the numerical result and the true derivative is the truncation error, arising because the limiting process h→0h \to 0 is replaced by a finite step. By deriving the difference formulas from Taylor or Lagrange series, we can find an explicit expression for this error and compute a bound on its magnitude.


Error Orders

The three difference formulas have different error characteristics:

MethodError OrderLeading Error TermEffect of dividing hh by 10
Forward DifferenceO(h)O(h)f′′(ξ)2 h\dfrac{f''(\xi)}{2}\,hError is divided by 10
Backward DifferenceO(h)O(h)f′′(ξ)2 h\dfrac{f''(\xi)}{2}\,hError is divided by 10
Central DifferenceO(h2)O(h^2)f′′′(ξ)6 h2\dfrac{f'''(\xi)}{6}\,h^2Error is divided by 100

For central difference, because the error scales as h2h^2, it shrinks much faster as hh decreases. Dividing hh by 10 divides the central difference error by 100, whereas the forward and backward errors only halve proportionally with hh.


Proof: Forward Difference Truncation Error

Graph showing the Lagrange interpolating polynomial P1(x) through x0 and x0+h compared to the true tangent at x0. The shaded region between the polynomial and the curve illustrates the curvature that gives rise to the truncation error. A red bracket labels the slope gap as f''(xi)/2 times h.

We derive the forward difference formula and its error term using Lagrange interpolation over two nodes: x0x_0 and x1=x0+hx_1 = x_0 + h.

Setting up the interpolant. Any function f(x)f(x) can be written as a first-degree Lagrange polynomial plus an error term:

f(x)=f(x0)x−x1x0−x1+f(x1)x−x0x1−x0+f′′(ξ)2(x−x0)(x−x1)f(x) = f(x_0)\frac{x - x_1}{x_0 - x_1} + f(x_1)\frac{x - x_0}{x_1 - x_0} + \frac{f''(\xi)}{2}(x - x_0)(x - x_1)

Differentiating with respect to xx:

f′(x)=f(x0)x0−x1+f(x1)x1−x0+f′′(ξ)2ddx[(x−x0)(x−x1)]f'(x) = \frac{f(x_0)}{x_0 - x_1} + \frac{f(x_1)}{x_1 - x_0} + \frac{f''(\xi)}{2}\frac{d}{dx}\left[(x - x_0)(x - x_1)\right]

Expanding the derivative of the product in the error term:

f′(x)=f(x0)x0−x1+f(x1)x1−x0+f′′(ξ)2(2x−x0−x1)f'(x) = \frac{f(x_0)}{x_0 - x_1} + \frac{f(x_1)}{x_1 - x_0} + \frac{f''(\xi)}{2}(2x - x_0 - x_1)

Evaluating at x=x0x = x_0. Since x1−x0=hx_1 - x_0 = h, we have x0−x1=−hx_0 - x_1 = -h. Substituting x1=x0+hx_1 = x_0 + h:

f′(x0)=f(x0)−h+f(x1)h+f′′(ξ)2(2x0−x0−(x0+h))f'(x_0) = \frac{f(x_0)}{-h} + \frac{f(x_1)}{h} + \frac{f''(\xi)}{2}(2x_0 - x_0 - (x_0 + h))

f′(x0)=f(x1)−f(x0)h+f′′(ξ)2(−h)f'(x_0) = \frac{f(x_1) - f(x_0)}{h} + \frac{f''(\xi)}{2}(-h)

f′(x0)=f(x0+h)−f(x0)h⏟Forward difference−f′′(ξ)2 h⏟Truncation error\boxed{f'(x_0) = \underbrace{\frac{f(x_0 + h) - f(x_0)}{h}}_{\text{Forward difference}} - \underbrace{\frac{f''(\xi)}{2}\,h}_{\text{Truncation error}}}

This confirms two things: the forward difference formula is an exact rearrangement of this identity, and the truncation error is the term −f′′(ξ)2h-\frac{f''(\xi)}{2}h, which is proportional to hh. Making hh smaller reduces this error linearly.


Proof: Backward Difference Truncation Error

Graph showing the Lagrange interpolating polynomial P1(x) through x0-h and x0 compared to the true tangent at x0. The shaded region between the polynomial and the curve illustrates the curvature causing the truncation error. A red bracket labels the slope gap as f''(xi)/2 times h.

We can derive the backward difference formula and its error term using Lagrange interpolation over two nodes: x0x_0 and x−1=x0−hx_{-1} = x_0 - h.

Setting up the interpolant. Just like the forward difference, f(x)f(x) can be written as a first-degree Lagrange polynomial plus an error term:

f(x)=f(x0)x−x−1x0−x−1+f(x−1)x−x0x−1−x0+f′′(ξ)2(x−x0)(x−x−1)f(x) = f(x_0)\frac{x - x_{-1}}{x_0 - x_{-1}} + f(x_{-1})\frac{x - x_0}{x_{-1} - x_0} + \frac{f''(\xi)}{2}(x - x_0)(x - x_{-1})

Differentiating with respect to xx:

f′(x)=f(x0)x0−x−1+f(x−1)x−1−x0+f′′(ξ)2(2x−x0−x−1)f'(x) = \frac{f(x_0)}{x_0 - x_{-1}} + \frac{f(x_{-1})}{x_{-1} - x_0} + \frac{f''(\xi)}{2}(2x - x_0 - x_{-1})

Evaluating at x=x0x = x_0. Since x0−x−1=hx_0 - x_{-1} = h and x−1−x0=−hx_{-1} - x_0 = -h. Substituting x−1=x0−hx_{-1} = x_0 - h:

f′(x0)=f(x0)h+f(x0−h)−h+f′′(ξ)2(2x0−x0−(x0−h))f'(x_0) = \frac{f(x_0)}{h} + \frac{f(x_0 - h)}{-h} + \frac{f''(\xi)}{2}(2x_0 - x_0 - (x_0 - h))

f′(x0)=f(x0)−f(x0−h)h+f′′(ξ)2(h)f'(x_0) = \frac{f(x_0) - f(x_0 - h)}{h} + \frac{f''(\xi)}{2}(h)

f′(x0)=f(x0)−f(x0−h)h⏟Backward difference+f′′(ξ)2 h⏟Truncation error\boxed{f'(x_0) = \underbrace{\frac{f(x_0) - f(x_0 - h)}{h}}_{\text{Backward difference}} + \underbrace{\frac{f''(\xi)}{2}\,h}_{\text{Truncation error}}}

The truncation error is proportional to hh, confirming that backward difference is also an O(h)O(h) approximation.


Further Reading: Proof of Central Difference Truncation Error

Proof: Central Difference Truncation Error

For the central difference formula, using Taylor series expansions is usually the clearest approach because it naturally reveals how the symmetric terms cancel out.

Setting up the Taylor series. We expand f(x)f(x) around x0x_0 to the third degree, evaluating at x0+hx_0 + h and x0−hx_0 - h:

f(x0+h)=f(x0)+hf′(x0)+h22f′′(x0)+h36f′′′(ξ1)f(x_0 + h) = f(x_0) + hf'(x_0) + \frac{h^2}{2}f''(x_0) + \frac{h^3}{6}f'''(\xi_1)

f(x0−h)=f(x0)−hf′(x0)+h22f′′(x0)−h36f′′′(ξ2)f(x_0 - h) = f(x_0) - hf'(x_0) + \frac{h^2}{2}f''(x_0) - \frac{h^3}{6}f'''(\xi_2)

Subtracting the two equations:

f(x0+h)−f(x0−h)=2hf′(x0)+h36(f′′′(ξ1)+f′′′(ξ2))f(x_0 + h) - f(x_0 - h) = 2hf'(x_0) + \frac{h^3}{6}(f'''(\xi_1) + f'''(\xi_2))

Notice how the f(x0)f(x_0) and h22f′′(x0)\frac{h^2}{2}f''(x_0) terms completely cancel out.

Consolidating the error term. This step relies on the Intermediate Value Theorem. Think of it like taking an average: f′′′(ξ1)+f′′′(ξ2)2\frac{f'''(\xi_1) + f'''(\xi_2)}{2}. Because we assume f′′′(x)f'''(x) is a continuous function, it must pass through this exact average value at some specific point ξ\xi somewhere between our two outer nodes (x0−hx_0 - h and x0+hx_0 + h).

Mathematically, this means f′′′(ξ1)+f′′′(ξ2)2=f′′′(ξ)\frac{f'''(\xi_1) + f'''(\xi_2)}{2} = f'''(\xi), which rearranges to f′′′(ξ1)+f′′′(ξ2)=2f′′′(ξ)f'''(\xi_1) + f'''(\xi_2) = 2f'''(\xi). This allows us to combine the two separate error evaluations into one:

f(x0+h)−f(x0−h)=2hf′(x0)+h36(2f′′′(ξ))f(x_0 + h) - f(x_0 - h) = 2hf'(x_0) + \frac{h^3}{6}(2f'''(\xi))

f(x0+h)−f(x0−h)=2hf′(x0)+h33f′′′(ξ)f(x_0 + h) - f(x_0 - h) = 2hf'(x_0) + \frac{h^3}{3}f'''(\xi)

Rearranging to solve for f′(x0)f'(x_0):

2hf′(x0)=f(x0+h)−f(x0−h)−h33f′′′(ξ)2hf'(x_0) = f(x_0 + h) - f(x_0 - h) - \frac{h^3}{3}f'''(\xi)

Divide everything by 2h2h:

f′(x0)=f(x0+h)−f(x0−h)2h⏟Central difference−f′′′(ξ)6 h2⏟Truncation error\boxed{f'(x_0) = \underbrace{\frac{f(x_0 + h) - f(x_0 - h)}{2h}}_{\text{Central difference}} - \underbrace{\frac{f'''(\xi)}{6}\,h^2}_{\text{Truncation error}}}

Because the h2h^2 terms in the Taylor series perfectly cancelled each other out, the leading error term contains h2h^2. This proves that the central difference method provides an O(h2)O(h^2) approximation.

Worked Example: Comparing Error Orders

Problem: Approximate the derivative of f(x)=ln⁡(x)f(x) = \ln(x) at x=2x = 2 using the forward, backward, and central difference formulas with step sizes h=0.1,0.01,0.001h = 0.1, 0.01, 0.001. Compare the errors with the exact derivative.

The exact derivative is f′(x)=1/xf'(x) = 1/x, so at x=2x = 2:

f′(2)=12=0.5f'(2) = \frac{1}{2} = 0.5

Step 1 — Compute the numerical derivatives

The three formulas are:

Forward=ln⁡(2+h)−ln⁡2h,Backward=ln⁡2−ln⁡(2−h)h,Central=ln⁡(2+h)−ln⁡(2−h)2h\text{Forward} = \frac{\ln(2+h) - \ln 2}{h}, \qquad \text{Backward} = \frac{\ln 2 - \ln(2-h)}{h}, \qquad \text{Central} = \frac{\ln(2+h) - \ln(2-h)}{2h}

The approximations are:

hhForwardErrorBackwardErrorCentralError
0.10.10.487901640.487901640.012098360.012098360.512932940.512932940.012932940.012932940.500417290.500417290.000417290.00041729
0.010.010.498754150.498754150.001245850.001245850.501254200.501254200.001254200.001254200.500004170.500004170.000004170.00000417
0.0010.0010.499875040.499875040.000124960.000124960.500125040.500125040.000125040.000125040.500000040.500000040.000000040.00000004

(All errors are absolute errors.)

Step 2 — Observe how the errors change

For the forward difference:

0.001245850.01209836≈9.7,0.000124960.00124585≈10\frac{0.00124585}{0.01209836} \approx 9.7, \qquad \frac{0.00012496}{0.00124585} \approx 10

Likewise, the backward difference error also decreases by approximately a factor of 10 whenever hh is divided by 10.

For the central difference:

0.000004170.00041729≈100,0.000000040.00000417≈100\frac{0.00000417}{0.00041729} \approx 100, \qquad \frac{0.00000004}{0.00000417} \approx 100

Its error decreases by approximately a factor of 100 whenever hh is divided by 10.


Worked Example: Upper Bound on Truncation Error

Problem: For f(x)=2sin⁡(x)+(3/2)cos⁡(2x)f(x) = 2\sin(x) + (3/2)\cos(2x) with step size h=0.1h = 0.1 over the interval (0.4,  1.2)(0.4,\; 1.2), compute the upper bound on the central difference truncation error.

The central difference truncation error bound is:

∣h26⋅f′′′(x)∣\left|\frac{h^2}{6} \cdot f'''(x)\right|

To find the upper bound, we need to maximise ∣f′′′(x)∣|f'''(x)| over (0.4,1.2)(0.4, 1.2), then multiply by h2/6h^2 / 6.

Step 1 — Compute f′′′(x)f'''(x)

Starting from:

f(x)=2sin⁡(x)+32cos⁡(2x)f(x) = 2\sin(x) + \frac{3}{2}\cos(2x)

f′(x)=2cos⁡(x)−3sin⁡(2x)f'(x) = 2\cos(x) - 3\sin(2x)

f′′(x)=−2sin⁡(x)−6cos⁡(2x)f''(x) = -2\sin(x) - 6\cos(2x)

f′′′(x)=−2cos⁡(x)+12sin⁡(2x)f'''(x) = -2\cos(x) + 12\sin(2x)

Step 2 — Bound ∣f′′′(x)∣|f'''(x)| using the triangle inequality

By the triangle inequality:

∣f′′′(x)∣=∣−2cos⁡(x)+12sin⁡(2x)∣≤∣−2cos⁡(x)∣+∣12sin⁡(2x)∣=2∣cos⁡(x)∣+12∣sin⁡(2x)∣|f'''(x)| = |-2\cos(x) + 12\sin(2x)| \leq |-2\cos(x)| + |12\sin(2x)| = 2|\cos(x)| + 12|\sin(2x)|

Now find the maximum of each term separately over the interval.

Bounding ∣cos⁡(x)∣|\cos(x)|: Since 0.40.4 to 1.21.2 radians lies in the first quadrant, cos⁡(x)>0\cos(x) > 0 and decreases with xx. Thus:

max⁡∣cos⁡(x)∣=cos⁡(0.4)≈0.9211\max|\cos(x)| = \cos(0.4) \approx 0.9211

Bounding ∣sin⁡(2x)∣|\sin(2x)|: For the maximum value, sin⁡(2x)=1\sin(2x) = 1 when 2x=π/22x = \pi/2, i.e. x=π/4≈0.785x = \pi/4 \approx 0.785, which falls inside (0.4,1.2)(0.4, 1.2). Therefore:

max⁡∣sin⁡(2x)∣=1\max|\sin(2x)| = 1

Combining the bounds:

∣f′′′(x)∣≤2(0.9211)+12(1)=1.8422+12=13.8422|f'''(x)| \leq 2(0.9211) + 12(1) = 1.8422 + 12 = 13.8422

Step 3 — Compute the error bound

Error≤h26×13.8422=(0.1)26×13.8422=0.016×13.8422≈0.02307\text{Error} \leq \frac{h^2}{6} \times 13.8422 = \frac{(0.1)^2}{6} \times 13.8422 = \frac{0.01}{6} \times 13.8422 \approx 0.02307