21.06.2014 Views

Numerical Methods Contents - SAM

Numerical Methods Contents - SAM

Numerical Methods Contents - SAM

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

ecursive definition:<br />

p i (t) ≡ y i , i = 0,...,n ,<br />

p i0 ,...,i m<br />

(t) = (t − t i 0<br />

)p i1 ,...,i m<br />

(t) − (t − t im )p i0 ,...,i m−1<br />

(t)<br />

t im − t i0<br />

.<br />

Aitken-Neville algorithm:<br />

n = 0 1 2 3<br />

t 0 y 0 =: p 0 (x) → ր<br />

p 01 (x) → ր<br />

p 012 (x) → ր<br />

p 0123 (x)<br />

t 1 y 1 =: p 1 (x) → ր<br />

p 12 (x) → ր<br />

p 123 (x)<br />

t 2 y 2 =: p 2 (x) → ր<br />

p 23 (x)<br />

t 3 y 3 =: p 3 (x)<br />

Example 8.3.3 (Timing polynomial evaluations).<br />

Comparison of the computational time needed for<br />

polynomial interpolation of<br />

{t i = i} i=1,...,n , {y i = √ i} i=1,...,n ,<br />

n = 3, ...,200, and evaluation in a point<br />

x ∈ [0,n].<br />

Minimum tic-toc-computational time<br />

Code 8.3.2: Aitken-Neville algorithm<br />

1 function v = ANipoleval ( t , y , x )<br />

2 for i =1: length ( y )<br />

3 for k= i −1:−1:1<br />

4 y ( k ) = y ( k +1) +( y ( k +1)−y ( k ) ) ∗ . . .<br />

5 ( x−t ( i ) ) / ( t ( i )−t ( k ) ) ;<br />

6 end<br />

7 end<br />

8 v = y ( 1 ) ;<br />

Computational time [s]<br />

10 0 Aitken−Neville scheme<br />

MATLAB polyfit<br />

Barycentric formula<br />

10 −1<br />

Legendre polynomials<br />

10 −2<br />

10 −3<br />

10 −4<br />

Polynomial degree<br />

10<br />

0 20 40 60 80 100 120 140 160 180 200<br />

over 100 runs ➙ −5<br />

Code 8.3.4: Timing polynomial evaluations<br />

(8.3.2)<br />

Ôº º¿<br />

1 time=zeros ( 1 , 4 ) ;<br />

2 f =@( x ) sqrt ( x ) ; % function to interpolate:<br />

3 for k=1:100<br />

4 res = [ ] ;<br />

5 for n=3:1:200 % n = increasing polynomial degree<br />

6 t = ( 1 : n ) ; y = f ( t ) ; x=n∗rand ;<br />

14 else , f i n r e s = min ( f i n r e s , res ) ; end<br />

7 t i c ; v1 = ANipoleval ( t , y , x ) ; time ( 1 ) = toc ;<br />

8 t i c ; v2 = i p o l e v a l ( t , y , x ) ; time ( 2 ) = toc ;<br />

9 t i c ; v3 = i n t p o l y v a l ( t , y , x ) ; time ( 3 ) = toc ;<br />

10 t i c ; v4 = i n t p o l y v a l _ l a g ( t , y , x ) ; time ( 4 ) = toc ;<br />

11 res = [ res ; n , time ] ;<br />

12 end<br />

13 i f ( k == 1) , f i n r e s = res ; Ôº¼ º¿<br />

This uses functions given in Code 8.3.0, Code 8.3.1 and the MATLAB function polyfit (with a<br />

clearly greater computational effort !)<br />

Code 8.3.5: MATLAB polynomial evaluation using built-in function polyfit<br />

1 function v= i p o l e v a l ( t , y , x )<br />

2 p = p o l y f i t ( t , y , length ( y )−1) ;<br />

3 v=polyval ( p , x ) ;<br />

Code 8.3.6: Lagrange polynomial interpolation and evaluation<br />

1 function p = i n t p o l y v a l _ l a g ( t , y , x )<br />

2 p=zeros ( size ( x ) ) ;<br />

3 for k =1: length ( t ) ; p=p + y ( k ) ∗ lagrangepoly ( x , k−1, t ) ; end<br />

4<br />

5 function L=lagrangepoly ( x , index , nodes )<br />

6 L=1;<br />

7 for j = [ 0 : index −1, index +1: length ( nodes ) −1];<br />

8 L = L .∗ ( x−nodes ( j +1) ) . / ( nodes ( index +1)−nodes ( j +1) ) ;<br />

9 end<br />

8.3.3 Extrapolation to zero<br />

Extrapolation is the same as interpolation but the evaluation point t is outside the interval<br />

[inf j=0,...,n t j , sup j=0,...,n t j ]. Assume t = 0.<br />

Problem: compute lim t→0 f(t) with prescribed precision, when the evaluation of the function<br />

y=f(t) is unstable for |t| ≪ 1.<br />

Known: existence of an asymptotic expansion in h 2<br />

Idea:<br />

f(h) = f(0) + A 1 h 2 + A 2 h 4 + · · · + A n h 2n + R(h) , A k ∈ K ,<br />

with remainder estimate |R(h)| = O(h 2n+2 ) for h → 0 .<br />

➀ evaluation of f(t i ) for different t i , i = 0,...,n, |t i | > 0.<br />

➁ f(0) ≈ p(0) with interpolation polynomial p ∈ P n , p(t i ) = f(t i ).<br />

Example 8.3.7 (Numeric differentiation through extrapolation).<br />

For a 2(n + 1)-times continuously differentiable function f : D ⊂ R ↦→ R, x ∈ D (Taylor sum in x<br />

with Lagrange residual)<br />

n∑<br />

T(h) :=<br />

f(x + h) − f(x − h)<br />

2h<br />

∼ f ′ 1 d 2k f<br />

(x) +<br />

(2k)! dx<br />

k=1<br />

2k(x)h2k +<br />

1<br />

Ôº½ º¿ ✸<br />

Ôº¾ º¿<br />

(2n + 2)! f(2n+2) (ξ(x)) .

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!