5 Numrical Analysis
Errors
Assume that r is the root of function f(x)=0.
- Forward Error: ∣r−xa∣
- Backward Error: f(xa)
- error magnification factor=relative backward errorrelative forward error
Basic Arithmetic
Evaluating a polynomial
Direct form:O(n2)
P(x)=a0+a1x+a2x2+...+anxn
Horner's method:O(n)
P(x)=a0+x(a1+x(a2+x∗(...(an−1+anx)))
Example:求二进制幂O(n)->O(logn)
an=ap(2)=abm2m+...+bi2i+b0
a2p+bi=a2p∗a or a2p
Multiplication
Calculate x=yz
we could devide y and z into 2 parts of 2n bits
Then follow the 4 equations, we only need 2 2n bits muliplications to calculate v and w
⎩⎨⎧u=(a+b)(c+d)v=acw=bdx=v2n+(u−v−w)22n+w For u, we could proof that we just need 1 2n bits muliplication + some addition and shift
T(n)=3T(n/2)+ln⇒T(n)=O(nlog23)
Solving Equations
Newton's Method
x0=initial guess
xi+1=xi−f′(xi)f(xi)
Convex Optimization
Convex combination: (x,y)→{αx+βy∣α+β=1,α,β≥0}
Convex set S: (x1,...,xk)∈S, then convex combination of the points x1, . . . , xk should ∈ S.
A function f : Rn→R is convex if ∀x,y and ∀α∈[0,1]
f(αx+(1−α)y)≤αf(x)+(1−α)f(y)
Convex Hull
Given n points in plane, S={(xi,yi)∣i=1,2,...,n} , Convex Hull(CH(S)): smallest polygon containing all points in S.
Finding upper tangent, same for lower tangent