UcenlyOpen in the app

Differential Equations & Numerical Methods · BE5B01DEN · Topic 2 of 13

Errors in computing

Week 2. Know absolute and relative error, the floating point bound, and why subtracting nearly equal numbers is dangerous.

Open the interactive lesson

Key ideas

Name the error you measure

For an exact x and an estimate x̂, the absolute error is E=x−x̂ and the relative error is ε=|E|/|x|. An error estimate is any number e with |E|≤e.

Floating point: the relative bound

Rounding x to p significant digits in base β gives fl(x)=d₁.d₂…d_p×β^e, and the relative error stays below half a unit in the last place relative to the leading digit.

Watch the subtraction

Sums of positive numbers, products and quotients keep the relative error under control, but a difference can magnify it by (|x|+|y|)/|x−y|. This is why close numbers should not be subtracted if you can rearrange the formula.

In one line: Relative error is what counts, and subtraction of near-equal numbers is where it explodes.

Formulas

Practice with worked solutions

Question 1

A decimal floating point system keeps p = 4 significant digits (β = 10). Use the bound to find the largest relative rounding error.

εx≤12β⋅β−p\varepsilon_x\le\tfrac12\beta\cdot\beta^{-p}
Worked solution

Answer: 0.0005

  1. 12⋅10⋅10−4=5⋅10−4=0.0005\tfrac12\cdot10\cdot10^{-4}=5\cdot10^{-4}=0.0005

Insert β=10 and p=4 into ½β¹⁻ᵖ.

Question 2

Estimates of x = 10.01 and y = 10.00 have relative errors at most 0.000001 each. Bound the relative error of x − y.

εx−y≤∣x∣+∣y∣∣x−y∣max⁡(εx,εy)\varepsilon_{x-y}\le\frac{|x|+|y|}{|x-y|}\max(\varepsilon_x,\varepsilon_y)
Worked solution

Answer: 0.002001

  1. 10.01+10.000.01=2001\frac{10.01+10.00}{0.01}=2001
  2. 2001⋅10−6=0.0020012001\cdot10^{-6}=0.002001

The factor (|x|+|y|)/|x−y| = 2001 magnifies the input error.

Question 3

Which operation can destroy the relative accuracy of the result?

  1. Adding two positive estimates
  2. Multiplying two estimates
  3. Subtracting two nearly equal estimates (correct)
  4. Taking the reciprocal of an estimate
Worked solution
  1. εx−y≤∣x∣+∣y∣∣x−y∣max⁡(εx,εy)→∞ (x→y)\varepsilon_{x-y}\le\frac{|x|+|y|}{|x-y|}\max(\varepsilon_x,\varepsilon_y)\to\infty\ (x\to y)

Subtraction of close numbers is the one operation with a large amplification factor.

More Differential Equations & Numerical Methods practice in Ucenly

Sources

Written by Ucenly. Based on the BE5B01DEN course materials: