Every numerical answer is an approximation. Knowing where errors come from, and how large they are, tells us how far an answer can be trusted.

Importance of Errors

A computer stores numbers with a fixed number of digits, and numerical methods stop after a finite number of steps. So the result differs from the true value. A small error in one step can grow over many steps and spoil the answer. A famous case is the Patriot missile failure of 1991, in which a tiny rounding error in the stored value of 0.1 second grew over 100 hours into a timing error of a third of a second. Understanding errors lets us choose methods and stopping rules that keep the answer accurate enough for its use.

Sources of Error

Inherent errors are present in the data itself, from measurement or from earlier calculation. Rounding errors come from keeping only a limited number of digits, as when 2/3 is stored as 0.6667. Truncation errors come from replacing an infinite process by a finite one, such as stopping a series after a few terms or stopping an iteration early. Human errors (blunders) are mistakes in the work. Errors can also be made worse by subtracting nearly equal numbers, which loses significant digits.

Definition: Absolute error. The magnitude of the difference between the true value and the approximate value, |true value − approximate value|.

Measures of Error

If X is the true value and x the approximate value, the absolute error is Ea = |X − x|. The relative error is Er = |X − x| / |X|, which compares the error with the size of the value. The percentage error is Ep = Er × 100. An error of 1 cm means little when measuring a road but much when measuring a coin, which is why relative error is often the better guide. A number is correct to n decimal places if its absolute error is at most 0.5 × 10⁻ⁿ, and to n significant digits if its relative error is suitably small.

Rounding and Chopping

To round a number to n digits, we look at the (n + 1)th digit and round up if it is 5 or more. To chop (truncate), we simply drop the extra digits. Rounding gives a maximum error of half a unit in the last place, while chopping can give up to a whole unit, so rounding is preferred.

Table 3.1: Types of error

Type Cause Example
Inherent Data or measurement g measured as 9.8
Rounding Limited digits 2/3 stored as 0.6667
Truncation Finite process Series stopped after 3 terms
Blunder Human mistake Copying 37 as 73

Example 3.1: Computing errors

Problem: The true value of π is 3.14159265. Find the absolute, relative and percentage error of the approximation 22/7 = 3.14285714.

Solution:

  1. Ea = |3.14159265 − 3.14285714| = 0.00126449.
  2. Er = 0.00126449 / 3.14159265 = 0.000402.
  3. Ep = 0.000402 × 100 = 0.0402 percent.

Result: The absolute error is about 0.00126, the relative error 0.000402, and the percentage error 0.04 percent.

import math
X, x = math.pi, 22 / 7
ea = abs(X - x)
print(round(ea, 8), round(ea / X, 6), round(ea / X * 100, 4))
print(0.1 + 0.2)

Output

0.00126449 0.000402 0.0402
0.30000000000000004

Common mistakes

  • Using absolute error alone to judge accuracy, without comparing it with the size of the value.
  • Chopping instead of rounding, which doubles the maximum error.
  • Subtracting nearly equal numbers and keeping all the digits as if they were significant.

Key takeaways

  • Absolute error is |X − x|, relative error is |X − x| / |X|.
  • Errors come from data, rounding, truncation and blunders.
  • Rounding errors can build up over many steps.
  • Rounding is more accurate than chopping.

Practice questions

  1. Define relative error.
  2. What is truncation error?
  3. Why does 0.1 + 0.2 not print exactly 0.3 in Python?

Answers to the practice questions

  1. The absolute error divided by the magnitude of the true value.
  2. The error from replacing an infinite process by a finite one.
  3. Because 0.1 and 0.2 cannot be stored exactly in binary, giving a rounding error.

Sources

  • Official BCA syllabus Mathematics Foundations to Computer Science II, course code 25BCA402DS01, Unit III