Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

9) Function errors

Today

  1. Conditioning and well posedness

  2. Relative and absolute errors

  3. Condition number

1. Conditioning and well-posedness

We say that a mathematical function f(x)f(x) is well conditioned if small changes in xx produce small changes in f(x)f(x). (What we mean by “small” will be made more precise.)

The function f(x)f(x) may represent a simple expression such as

  • f(x):=2xf(x) := 2 x

  • f(x):=xf(x) := \sqrt{x}

  • f(x):=log⁡xf(x) := \log{x}

  • f(x):=x−1f(x) := x - 1

A function may also represent something more complicated, implementable on a computer or by physical experiment.

  • Find the positive root of the polynomial t2+(1−x)t−x.t^2 + (1-x)t - x.

  • Find the eigenvectors of the matrix

    A(x)=[110x].A(x) = \begin{bmatrix} 1 & 1 \\ 0 & x \end{bmatrix} .
  • Find how much the bridge flexes when the truck of mass xx drives over it.

  • Find the length of the rubber band when it finally snaps, as a function of temperature xx during manufacturing.

  • Find the time at which the slope avalanches as a function of the wind speed xx during the storm.

  • Find the probability that the slope avalanches in the next 48 hours as a function of the wind speed xx during the storm.

  • Find the probability that the hurricane makes landfall as a function of the observations xx.

Specification

  • Some of these problems are fully-specified

  • Others involve sophisticated models and ongoing community research problems.

  • In some cases, the models that are computable may incur greater uncertainty than the underlying system. In such cases, an analog experiment might produce smoother variation of the output as the problem data xx are varied.

  • In others, the model might be better behaved than what it seeks to model.

  • Some of these problems may be ill-posed

Well-posedness

A problem is said to be well-posed if

  1. a solution exists,

  2. the solution is unique, and

  3. the solution depends continuously on the problem specification.

Mathematically, continuous variation in part 3 can be arbitrarily fast, but there may be measurement error, manufacturing tolerances, or incomplete specification in real-world problems, such that we need to quantify part 3. This is the role of conditioning.

Example:

Computing exe^x

ex=∑k=0∞xk/k!=1+x+x22!+x33!+⋯e^x = \sum_{k=0}^{\infty} x^k/k! = 1 + x + \frac{x^2}{2!} + \frac{x^3}{3!} + \dotsb
1.445646891729250136554224997792468345749669676277240766303534163549513721620773e-16
4.440892098500626e-16
  • How accurate is it?

Loading...
Loading...
GKS: Possible loss of precision in routine SET_WINDOW

What’s happening?

  • We’re computing f(x)=exf(x) = e^x for values of xx near zero.

  • This function is well approximated by 1+x1 + x.

  • Values of yy near 1 cannot represent every value.

  • After rounding, the error in our computed output f~(x)\tilde f(x) is of order ϵmachine\epsilon_{\text{machine}}.

2. Absolute and Relative Errors

Absolute Error

∣f~(x)−f(x)∣\lvert \tilde f(x) - f(x) \rvert

Relative Error

∣f~(x)−f(x)∣∣f(x)∣\frac{\lvert \tilde f(x) - f(x) \rvert}{\lvert f(x) \rvert}

Suppose I want to compute ex−1e^x - 1

Loading...

What now?

  • We’re capable of representing outputs with 16 digits of accuracy

  • Yet our algorithm myexp(x) - 1 can’t find them

  • We can’t recover without modifying our code

Modify the code

myexpm1 (generic function with 1 method)
Loading...

Plot relative error

Loading...

Floating point representation is relative (see float.exposed)

IEEE 754 double-precision floating-point format

Let fl⁡\operatorname{fl} round to the nearest floating point number.

fl⁡(x)=x(1+ϵ),where∣ϵ∣≤ϵmachine\operatorname{fl}(x) = x (1 + \epsilon), \quad \text{where} |\epsilon| \le \epsilon_{\text{machine}}

This also means that the relative error in representing xx is small:

∣fl⁡(x)−x∣∣x∣≤ϵmachine\frac{|\operatorname{fl}(x) - x|}{|x|} \le \epsilon_{\text{machine}}
Loading...

Exact arithmetic, correctly rounded

Take an elementary math operation ∗* (addition, subtraction, multiplication, division), and the discrete operation that our computers perform, ⊛\circledast. Then

x⊛y:=fl⁡(x∗y)x \circledast y := \operatorname{fl}(x * y)

with a relative accuracy ϵmachine\epsilon_{\text{machine}},

∣(x⊛y)−(x∗y)∣∣x∗y∣≤ϵmachine.\frac{|(x \circledast y) - (x * y)|}{|x * y|} \le \epsilon_{\text{machine}} .

How do operations compose?

Is this true?

∣((x⊛y)⊛z)−((x∗y)∗z)∣∣(x∗y)∗z∣≤?ϵmachine\frac{\Big\lvert \big((x \circledast y) \circledast z\big) - \big((x * y) * z\big) \Big\rvert}{|(x * y) * z|} \le^? \epsilon_{\text{machine}}
Loading...

3. Condition number

What sort of functions cause small errors to become big?

Consider a function f:X→Yf: X \to Y and define the absolute condition number

κ^=lim⁡δ→0max⁡∣δx∣<δ∣f(x+δx)−f(x)∣∣δx∣=max⁡δx∣δf∣∣δx∣.\hat\kappa = \lim_{\delta \to 0} \max_{|\delta x| < \delta} \frac{|f(x + \delta x) - f(x)|}{|\delta x|} = \max_{\delta x} \frac{|\delta f|}{|\delta x|}.

If ff is differentiable, then κ^=∣f′(x)∣\hat\kappa = |f'(x)|.

Floating point offers relative accuracy, so it’s more useful to discuss relative condition number,

κ=max⁡δx∣δf∣/∣f∣∣δx∣/∣x∣=max⁡δx[∣δf∣/∣δx∣∣f∣/∣x∣]\kappa = \max_{\delta x} \frac{|\delta f|/|f|}{|\delta x|/|x|} = \max_{\delta x} \Big[ \frac{|\delta f|/|\delta x|}{|f| / |x|} \Big]

or, if ff is differentiable,

κ=∣f′(x)∣∣x∣∣f∣.\kappa = |f'(x)| \frac{|x|}{|f|} .