Numerical AnalysisNumbers on a Computer

Absolute and Relative Error

Absolute error is |approximation − true value|; relative error divides by |true value| and tells how many significant digits are correct.

Not started Jump to practice

Almost every number a computer produces is an approximation: a rounded constant, a truncated series, the last step of an iteration. Before we can compare methods we need a precise way to say how good an approximation is. You met the idea as Percent Error; here we sharpen it and connect it to scientific notation and significant digits.

Let $x$ be the true value and $\tilde{x}$ an approximation of it. The absolute error is $$|\tilde{x} - x|,$$ and, when $x \ne 0$, the relative error is $$\frac{|\tilde{x} - x|}{|x|}.$$ The absolute error carries the units of $x$. The relative error has no units; multiplied by 100 it is the percent error.

Key idea

Absolute error measures the size of the mistake. Relative error measures it in units of the true value, so it says how many leading digits are right: a relative error near $10^{-t}$ means about $t$ correct significant digits.

Why it works

Write $x = m \times 10^{e}$ with $1 \le |m| < 10$. If $\tilde{x}$ agrees with $x$ through the $t$-th significant digit, their difference is at most about half a unit in that place, $\tfrac{1}{2} \times 10^{e - t + 1}$. Dividing by $|x| \ge 10^{e}$ gives a relative error of at most $5 \times 10^{-t}$, whatever $e$ is. The size of the number cancels out; that is why relative error is the natural measure for numbers of any size, and why floating-point arithmetic is designed around it.

Worked example: Both errors

A tank holds $x = 250$ L, and a gauge reads $\tilde{x} = 248$ L. Find the absolute and relative errors.
  1. Absolute error: $|248 - 250| = 2$ L.
  2. Relative error: $\frac{2}{250} = 0.008$, or $0.8\%$.
  3. Divide by the true value, $250$, not by the reading.

Answer: $2$ L and $0.008$

Worked example: Comparing approximations of different sizes

Which is the better approximation: $3.14$ for $\pi$, or $384{,}000$ km for the average distance to the Moon, $384{,}400$ km?
  1. Absolute errors: $|3.14 - \pi| \approx 0.00159$ and $400$ km. The second looks enormous.
  2. Relative errors: $\frac{0.00159}{3.14159} \approx 5.1 \times 10^{-4}$ and $\frac{400}{384{,}400} \approx 1.0 \times 10^{-3}$.
  3. Measured relative to their size, $3.14$ is about twice as good, though both are right to about 3 significant digits.

Answer: $3.14$ for $\pi$

A room measured to the nearest centimeter and the distance to the Moon rounded to the nearest thousand km. The absolute error depends on the size and the units of the number; the relative error does not.

A common way to make "correct digits" exact: $\tilde{x}$ approximates $x$ to $t$ significant digits when $t$ is the largest whole number with $$\frac{|\tilde{x} - x|}{|x|} \le 5 \times 10^{-t}.$$

Worked example: Counting significant digits

How many significant digits does $\tilde{x} = 2.718$ have as an approximation of $e = 2.71828183\ldots$?
  1. Absolute error: $|2.718 - 2.71828183| = 0.00028183$.
  2. Relative error: $0.00028183 \div 2.71828183 \approx 1.04 \times 10^{-4}$.
  3. It is at most $5 \times 10^{-4}$ but more than $5 \times 10^{-5}$, so $t = 4$, matching the 4 digits written.

Answer: $4$

Common mistake

Dividing by the approximation instead of the true value, or comparing absolute errors of numbers of very different sizes. An error of 400 km in the distance to the Moon is better, relatively, than an error of 1 m in the length of a room. Quick check: a relative error should not change when you change units (meters to centimeters); an absolute error does.
In practice the true value is unknown. Error bounds, estimates and comparisons between two approximations take its place, as later topics show.

Practice

Pass with 3 right answers, the last 2 in a row. Each right answer earns 1 XP.

Loading practice…

Builds on

Leads to

Sources and further reading

  • Tobin A. Driscoll and Richard J. Braun, Fundamentals of Numerical Computation (University of Delaware, free online edition): chapter "Introduction", section "Floating-point numbers" (absolute and relative accuracy)
  • Autar Kaw, Holistic Numerical Methods (University of South Florida): Introduction to Numerical Methods, "Measuring Errors"
@teddyrookbook GitHub