math381lab51111

6
University of Alberta LAB 5. Neville’s iterated interpolation Guangrui (Garry) Li [email protected] Department of Mathematical and Statistical Sciences University of Alberta Oct., 2006 G. Li – p.

description

neville

Transcript of math381lab51111

Page 1: math381lab51111

University of Alberta

LAB 5. Neville’s iteratedinterpolation

Guangrui (Garry) [email protected]

Department of Mathematical and Statistical Sciences

University of Alberta

Oct., 2006 G. Li – p. 1

Page 2: math381lab51111

University of Alberta

Theorem behind the Neville’smethodLet f be defined at x0, x1, ..., xk, and let xj and xi betwo distinct numbers in this set. Then

P (x) =

(x − xj)P0,1,.,j−1,j+1,.,k(x) − (x − xi)P0,1,.,i−1,i+1,.,k(x)

(xi − xj)

describes the kth Lagrange polynomial thatinterpolates f at the k+1 points x0, x1, ..., xk

Oct., 2006 G. Li – p. 2

Page 3: math381lab51111

University of Alberta

Neville’s algorithmInput: Numbers x, x0, x1, ...xn;Values f(x0), f(x1), ...f(xn) as the first columnQ0,0, Q1,0, ..., Qn,0 of Q

Output: the table Q with P (x) = Qn,n

Step 1For i=1,2,...,n

for j=1,2,...,i

set Qi,j =(x−xi−j)Qi,j−1−(x−xi)Qi−1,j−1

xi−xi−j

Step 2. Output(Q)Stop

Oct., 2006 G. Li – p. 3

Page 4: math381lab51111

University of Alberta

Matlab codefunction [Table,Px]=neville(FUN,xn,x);

n=length(xn)-1;Table(:,1)=xn’;if isstr(FUN)==1;

Table(:,2)=feval(FUN, xn’);else

Table(:,2)=FUN’;end;for i=2:n+1;

for j=3:i+1;Table(i,j)=((x-xn(i))*Table(i-1,j-1)-...(x-xn(i-j+2))*Table(i,j-1))/(xn(i-j+2)-xn(i));

end;end;Px=Table(n+1,n+2);

Oct., 2006 G. Li – p. 4

Page 5: math381lab51111

University of Alberta

saved results of matlabxn=0:0.25:0.75f=[ 1 1.64872 2.71828 4.48169]neville31(f,xn,0.43)0 1.0000 0 0 00.2500 1.6487 2.1158 0 00.5000 2.7183 2.4188 2.3764 00.7500 4.4817 2.2245 2.3489 2.3606

xn=[-1 -0.5 0 0.5]f=[0.86199480 0.95802009 1.0986123 1.2943767]neville31(f,xn,0.25)-1.0000 0.8620 0 0 0-0.5000 0.9580 1.1021 0 00 1.0986 1.1689 1.1856 00.5000 1.2944 1.1965 1.1896 1.1889

Oct., 2006 G. Li – p. 5

Page 6: math381lab51111

University of Alberta

Exercise• 1. f(0.43) if

f(0) = 1, f(0.25) = 1.64872

f(0.5) = 2.71828, f(0.75) = 4.48169

solution: 2.36060473408

• 2. f(0.25) if

f(−1) = 0.86199480, f(−0.5) = 0.95802009

f(0) = 1.0986123, f(0.5) = 1.2943767

solution: 1.188935146875

Oct., 2006 G. Li – p. 6