Evaluating a polynomial
Direct form:O( n 2 n^2 n2)
P ( x ) = a 0 + a 1 x + a 2 x 2 + . . . + a n x n P(x)=a_0+a_1x+a_2x^2+...+a_nx^n P(x)=a0+a1x+a2x2+...+anxn
Horner’s method:O(n)
P ( x ) = a 0 + x ( a 1 + x ( a 2 + x ∗ ( . . . ( a n − 1 + a n x ) ) ) P(x)=a_0+x(a_1+x(a_2+x*(...(a_{n-1}+a_nx))) P(x)=a0+x(a1+x(a2+x∗(...(an−1+anx)))
Example:求二进制幂O(n)->O( l o g 2 n log_2n log2n)
a n = a p ( 2 ) a^n=a^{p(2)} an=ap(2) = a b m 2 m + . . . + b i 2 i + b 0 =a^{b_m2^m+...+b_i2^i+b_0} =abm2m+...+bi2i+b0
a 2 p + b i = a 2 p ∗ a a^{2p+b_i}=a^{2p}*a a2p+bi=a2p∗a or a 2 p a^{2p} a2p
Errors
Assume that r is the root of function f(x)=0.
Forward Error:
∣
r
−
x
a
∣
|r-x_a|
∣r−xa∣
Backward Error:
f
(
x
a
)
f(x_a)
f(xa)
Solving Equations
Newton’s Method
x
0
=
i
n
i
t
i
a
l
g
u
e
s
s
x_0=initial\ guess
x0=initial guess
x
i
+
1
=
x
i
−
f
(
x
i
)
f
′
(
x
i
)
x_{i+1}=x_i-\frac{f(x_i)}{f'(x_i)}
xi+1=xi−f′(xi)f(xi)
NaN:not a number
Convex Optimization
Convex combination: ( x , y ) → { α x + β y ∣ α + β = 1 , α , β ≥ 0 } (x,y)\rightarrow\{\alpha x + \beta y|\alpha + \beta =1, \alpha,\beta \geq 0\} (x,y)→{αx+βy∣α+β=1,α,β≥0}
Convex set S: ( x 1 , . . . , x k ) ∈ S (x1, . . . , xk) \in S (x1,...,xk)∈S, then convex combination of the points x1, . . . , xk should ∈ \in ∈ S.
A function f : R n → R R^n \rightarrow R Rn→R is convex if ∀ x , y \forall x, y ∀x,y and ∀ α ∈ [ 0 , 1 ] \forall \alpha \in [0, 1] ∀α∈[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) f(αx+(1−α)y)≤αf(x)+(1−α)f(y)