Truncation error

From HandWiki
Revision as of 19:31, 6 February 2024 by John Stpola (talk | contribs) (simplify)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Short description: Error from taking a finite sum of an infinite series

In numerical analysis and scientific computing, truncation error is an error caused by approximating a mathematical process.[1][2]

Examples

Infinite series

A summation series for [math]\displaystyle{ e^x }[/math] is given by an infinite series such as [math]\displaystyle{ e^x=1+ x+ \frac{x^2}{2!} + \frac{x^3}{3!}+ \frac{x^4}{4!}+ \cdots }[/math]

In reality, we can only use a finite number of these terms as it would take an infinite amount of computational time to make use of all of them. So let's suppose we use only three terms of the series, then [math]\displaystyle{ e^x\approx 1+x+ \frac{x^2}{2!} }[/math]

In this case, the truncation error is [math]\displaystyle{ \frac{x^3}{3!}+\frac{x^4}{4!}+ \cdots }[/math]

Example A:

Given the following infinite series, find the truncation error for x = 0.75 if only the first three terms of the series are used. [math]\displaystyle{ S = 1 + x + x^2 + x^3 + \cdots, \qquad \left|x\right|\lt 1. }[/math]

Solution

Using only first three terms of the series gives [math]\displaystyle{ \begin{align} S_3 &= \left(1+x+x^2\right)_{x=0.75} \\ & = 1+0.75+\left(0.75\right)^2 \\ &= 2.3125 \end{align} }[/math]

The sum of an infinite geometrical series [math]\displaystyle{ S = a + ar + ar^2 + ar^3 + \cdots,\ r\lt 1 }[/math] is given by [math]\displaystyle{ S = \frac{a}{1-r} }[/math]

For our series, a = 1 and r = 0.75, to give [math]\displaystyle{ S=\frac{1}{1-0.75}=4 }[/math]

The truncation error hence is [math]\displaystyle{ \mathrm{TE} = 4 - 2.3125 = 1.6875 }[/math]

Differentiation

The definition of the exact first derivative of the function is given by [math]\displaystyle{ f'(x) = \lim_{h \to 0} \frac{f(x+h)-f(x)}{h} }[/math]

However, if we are calculating the derivative numerically, [math]\displaystyle{ h }[/math] has to be finite. The error caused by choosing [math]\displaystyle{ h }[/math] to be finite is a truncation error in the mathematical process of differentiation.

Example A:

Find the truncation in calculating the first derivative of [math]\displaystyle{ f(x)=5x^3 }[/math] at [math]\displaystyle{ x=7 }[/math] using a step size of [math]\displaystyle{ h=0.25 }[/math]

Solution:

The first derivative of [math]\displaystyle{ f(x)=5x^3 }[/math] is [math]\displaystyle{ f'(x) = 15x^2, }[/math] and at [math]\displaystyle{ x=7 }[/math], [math]\displaystyle{ f'(7) = 735. }[/math]

The approximate value is given by [math]\displaystyle{ f'(7) = \frac{f(7+0.25)-f(7)}{0.25} = 761.5625 }[/math]

The truncation error hence is [math]\displaystyle{ \mathrm{TE} = 735 - 761.5625 = -26.5625 }[/math]

Integration

The definition of the exact integral of a function [math]\displaystyle{ f(x) }[/math] from [math]\displaystyle{ a }[/math] to [math]\displaystyle{ b }[/math] is given as follows.

Let [math]\displaystyle{ f: [a,b] \to \Reals }[/math] be a function defined on a closed interval [math]\displaystyle{ [a,b] }[/math] of the real numbers, [math]\displaystyle{ \Reals }[/math], and [math]\displaystyle{ P = \left \{[x_0,x_1], [x_1,x_2], \dots,[x_{n-1},x_n] \right \}, }[/math] be a partition of I, where [math]\displaystyle{ a = x_0 \lt x_1 \lt x_2 \lt \cdots \lt x_n = b. }[/math] [math]\displaystyle{ \int_{a}^b f(x) \, dx = \sum_{i=1}^{n} f(x_i^*)\, \Delta x_i }[/math] where [math]\displaystyle{ \Delta x_i = x_i - x_{i-1} }[/math] and [math]\displaystyle{ x_i^* \in [x_{i-1}, x_i] }[/math].

This implies that we are finding the area under the curve using infinite rectangles. However, if we are calculating the integral numerically, we can only use a finite number of rectangles. The error caused by choosing a finite number of rectangles as opposed to an infinite number of them is a truncation error in the mathematical process of integration.

Example A.

For the integral [math]\displaystyle{ \int_{3}^{9}x^{2}{dx} }[/math] find the truncation error if a two-segment left-hand Riemann sum is used with equal width of segments.

Solution

We have the exact value as [math]\displaystyle{ \begin{align} \int_{3}^{9}{x^{2}{dx}} &= \left[ \frac{x^{3}}{3} \right]_{3}^{9} \\ & = \left[ \frac{9^{3} - 3^{3}}{3} \right] \\ & = 234 \end{align} }[/math]

Using two rectangles of equal width to approximate the area (see Figure 2) under the curve, the approximate value of the integral

[math]\displaystyle{ \begin{align} \int_3^9 x^2 \, dx &\approx \left. \left(x^2\right) \right|_{x = 3}(6 - 3) + \left. \left(x^2\right) \right|_{x = 6}(9 - 6) \\ & = (3^2)3 + (6^2)3 \\ &= 27 + 108 \\ &= 135 \end{align} }[/math]

[math]\displaystyle{ \begin{align} \text{Truncation Error} &= \text{Exact Value} - \text{Approximate Value} \\ &= 234 - 135 \\ &= 99. \end{align} }[/math]

Occasionally, by mistake, round-off error (the consequence of using finite precision floating point numbers on computers), is also called truncation error, especially if the number is rounded by chopping. That is not the correct use of "truncation error"; however calling it truncating a number may be acceptable.

Addition

Truncation error can cause [math]\displaystyle{ (A+B)+C \neq A+(B+C) }[/math] within a computer when [math]\displaystyle{ A = -10^{25}, B = 10^{25}, C = 1 }[/math] because [math]\displaystyle{ (A+B)+C = (0)+C = 1 }[/math] (like it should), while [math]\displaystyle{ A+(B+C) = A+(B)=0 }[/math]. Here, [math]\displaystyle{ A+(B+C) }[/math] has a truncation error equal to 1. This truncation error occurs because computers do not store the least significant digits of an extremely large integer.

See also

  • Quantization error

References

  1. Atkinson, Kendall E. (1989) (in English). An Introduction to Numerical Analysis (2nd ed.). New York: Wiley. p. 20. ISBN 978-0-471-62489-9. OCLC 803318878. https://www.worldcat.org/oclc/803318878. 
  2. Stoer, Josef; Bulirsch, Roland (2002) (in English), Introduction to Numerical Analysis (3rd ed.), Princeton, N.J.: Recording for the Blind & Dyslexic, OCLC 50556273, https://www.worldcat.org/oclc/50556273, retrieved 2022-02-08