Suppose you’d like to guage the perform
for small values of z, say z = 10−8. This instance comes from [1].
The Python code
from numpy import exp def f(z): return (exp(z) - 1 - z)/z**2 print(f(1e-8))
prints -0.607747099184471.
Now suppose you believe you studied numerical difficulties and compute your outcome to 50 decimal locations utilizing bc -l
.
scale = 50 z = 10^-8 (e(z) - 1 - z)/z^2
Now you get u(z) = .50000000166666667….
This means authentic calculation was utterly improper. What’s occurring?
For small z,
ez ≈ 1 + z
and so we lose precision when straight evaluating the numerator within the definition of u. In our instance, we misplaced all precision.
The imply worth theorem from complicated evaluation says that the worth of an analytic perform at a degree equals the typical of the values over a circle centered at that time. If we take the typical of 16 values in a circle of radius 1 round our level, we get full accuracy. The Python code
def g(z): N = 16 ws = z + exp(2j*pi*arange(N)/N) return sum(f(ws))/N
returns
0.5000000016666668 + 8.673617379884035e-19j
which departs from the outcome calculated with bc
within the sixteenth decimal place.
At a excessive degree, we’re avoiding numerical difficulties by averaging over factors removed from the tough area.
[1] Lloyd N. Trefethen and J. A. C. Weideman. The Exponentially Convergent Trapezoid Rule. SIAM Evaluate. Vol. 56, No. 3. pp. 385–458.