Skip to main content

5 Numrical Analysis

Errors​

Assume that r is the root of function f(x)=0f(x)=0.

  • Forward Error: ∣r−xa∣|r-x_a|
  • Backward Error: f(xa)f(x_a)
  • error magnification factor=relative forward errorrelative backward error\text{error magnification factor} = \frac{\text{relative forward error}}{\text{relative backward error}}

Basic Arithmetic​

Evaluating a polynomial​

Direct form:O(n2n^2)

P(x)=a0+a1x+a2x2+...+anxnP(x)=a_0+a_1x+a_2x^2+...+a_nx^n

Horner's method:O(n)

P(x)=a0+x(a1+x(a2+x∗(...(an−1+anx)))P(x)=a_0+x(a_1+x(a_2+x*(...(a_{n-1}+a_nx)))

Example:求二进制幂O(n)->O(log⁡n\log n)

an=ap(2)a^n=a^{p(2)}=abm2m+...+bi2i+b0=a^{b_m2^m+...+b_i2^i+b_0}

a2p+bi=a2p∗aa^{2p+b_i}=a^{2p}*a or a2pa^{2p}

Multiplication​

Calculate x=yzx=yz

we could devide y and z into 2 parts of n2\frac n2 bits

yab
zcd

Then follow the 4 equations, we only need 2 n2\frac n2 bits muliplications to calculate v and w

{u=(a+b)(c+d)v=acw=bdx=v2n+(u−v−w)2n2+w\begin{cases} u = (a+b)(c+d) \\ v = ac \\ w = bd \\ x= v2^n + (u - v - w)2^{\frac n2} + w \end{cases}

For u, we could proof that we just need 1 n2\frac n2 bits muliplication + some addition and shift

20240207234335

T(n)=3T(n/2)+ln⇒T(n)=O(nlog⁡23)T(n) = 3T(n/2) + ln \Rightarrow T(n) = O(n^{\log_2^3})

Solving Equations​

Newton's Method

x0=initial guessx_0=initial\ guess

xi+1=xi−f(xi)f′(xi)x_{i+1}=x_i-\frac{f(x_i)}{f'(x_i)}

Convex Optimization​

Convex combination: (x,y)→{αx+βy∣α+β=1,α,β≥0}(x,y)\rightarrow\{\alpha x + \beta y|\alpha + \beta =1, \alpha,\beta \geq 0\}

Convex set S: (x1,...,xk)∈S(x1, . . . , xk) \in S, then convex combination of the points x1, . . . , xk should ∈\in S.

A function f : Rn→RR^n \rightarrow R is convex if ∀x,y\forall x, y and ∀α∈[0,1]\forall \alpha \in [0, 1]

f(αx+(1−α)y)≤αf(x)+(1−α)f(y)f(\alpha x + (1-\alpha) y) \leq \alpha f(x) + (1-\alpha) f(y)

20230512172643

Convex Hull​

Given n points in plane, S={(xi,yi)∣i=1,2,...,n}S = \{(x_i, y_i)| i = 1,2, ... , n\} , Convex Hull(CH(S)): smallest polygon containing all points in S.

20240207235238

Finding upper tangent, same for lower tangent

20240207235321