Lecture 5 Flashcards
Relative error
er = |x-^x|/|x|
Independent of magnitude (≠ to absolute errors)
Significant digits/figures
digits carrying meaningful information
- 00350 = 3 digits
- 14159 = 6 digits
- 00035 = 2 digits
Relation relative error / accurate digits
rel_er <= 10^{-n+1}, n is the number of accurate significant digits
You know a tree is 170 ft tall, but your tool has a rel_err=10%. What’s the max measurement to expect?
187 ft
^x = x(1 ± err)
You measure 170 ft tall with a measurement tool rel_err=10%, what’s the actual min height?
155 ft
x = ^x / (1 ± err)
After rounding, a number has 5 digits, what’s an estimate of the upper bound of the relative error?
10^-4 (n=5, rel_err <= 10^{-n+1})
Sources of error
- rounding (1/3 = 0.333…)
- truncation (approx. math exp cos/sin…)
f(x) = 2x^2 + 27x + 1000
Big O with x→0, x→∞
- |f(x)| <= M*1, f(x) = O(1)
2. |f(x)| <= Mx^2, f(x)=O(x^2)
Taylor approximation x_0
f(x) = ∑i=0→∞ f^(i)(x_0)(x-x_0)^i/i!
Taylor approximation error
h=x-x_0
error = |f(x) - ∑(0→n) f^(i)(x0)h^i/i!| = |∑(n+1→∞) f^(i)(x0)h^i/i!|
Order n → error O(h^{n+1}) – exponent of the dominant term of the remainder (which is the error)
If ξ \in (x0,x), then error <= f^(n+1)(ξ)/(n+1)! (h)^{n+1} = M(h)^{n+1}
Degree of Taylor app?
Terms from 0→n (first n+1) gives approximation of degree n (in range(n+1)…) that is s.t. x^n is in the expression
Find error / order on a graph f(x) = error (loglog)
e = ax^n
log(e) = log(a)+n.log(x)
n=(y2-y1)/(x2-x1) is the slope → error O(x^4)
Approximation order n-1!
Factorial python
from math import factorial
Calculate python (sin(√x))^(2)(0)
import sympy as sp sp.init_printing() sp.var("x") expr = sp.sin(sp.sqrt(x)) expr.diff(x,2).subs(x,0).evalf()
Generate 1000 points between -1 and 1
np.linspace(-1, 1, 1000)
The measured distance between Champaign and Chicago is 277.5 miles with a relative error of 2%, and the measured distance between Chicago and Milwaukee is 225.1 miles with a relative error of 6%
The distance between Champaign to Milwaukee can be given by the sumation of both distances. In the worst case, what is the relative error (in percent) of the distance between Champaign to Milwaukee?
err_{X+Y} = \frac{|\hat{x}/(1-err_X) + \hat{y}/(1-err_Y) - (\hat{x}+\hat{y})|}{|\hat{x}/(1-err_X) + \hat{y}/(1-err_Y)|} = 3.83%
If the error in a computation behaves as O(h^6) depending on a mesh size parameter h, and if the error for h=0.5 is 0.01, what will the error be for h=0.7?
e2 = e1.(h2/h1)^6 = 0.0752
If the error for h=0.01 is 0.08 and the error for h=0.005 is 0.01, what power of h would you expect for this calculation?
n = log(e2/e1)/log(h2/h1)
If the algorithm takes 8 seconds with n=1200 and it takes 2 seconds with n=600, what is the order of the time cost?
8 = c.1200^a 2 = c.600^a a = log(8/2)/log(1200/600)
def taylor_exp(n, x0)
import sympy as sp
from math import factorial
sp.init_printing()
sp.var(“x”)
def taylor_exp(n, x0): taylor = 0 for i in range(n+1): taylor += f.diff(x, i).subs(x, x0)/factorial(i) * (x-x0)**i return taylor