Professional Documents
Culture Documents
5 1.519
Problem: Estimate the viscosity when the
temperature is 8 degrees. 10 1.308
15 1.140
Introduction
Estimation of intermediate values between precise data
points. The most common method is polynomial
interpolation:
f ( x) a0 a1 x a2 x an x
2 n
n=3 n=4
n=2
𝑓1 (𝑥) = 𝑏0 + 𝑏1 𝑥 − 𝑥0
Example :
Find a polynomial that interpolates (1,2) and (2,4).
42
f1 ( x) 2 x 1 2 x
2 1
Quadratic Interpolation
• Given any three points: x0 , f ( x0 ), x1, f ( x1 ), and x2 , f ( x2 )
• The polynomial that interpolates the three points is:
f 2 ( x) b0 b1 x x0 b2 x x0 x x1
where :
b0 f ( x0 )
f ( x1 ) f ( x0 )
b1 f [ x0 , x1 ]
x1 x0
f ( x2 ) f ( x1 ) f ( x1 ) f ( x0 )
x2 x1 x1 x0
b2 f [ x0 , x1 , x2 ]
x2 x0
General nth Order Interpolation
Given any n+1 points: x0 , f ( x0 ), x1 , f ( x1 ), ..., xn , f ( xn )
The polynomial that interpolates all points is:
i 1
x x j
n
f n ( x) F [ x0 , x1 ,..., xi ]
i 0 j 0
Divided Difference Table
x F[ ] F[ , ] F[ , , ]
xi f(xi)
0 -5 2 -4
1 -3 6
0 -5
-1 -15 1 -3
-1 -15
Entries of the divided difference table are
obtained from the data table using simple
operations.
Divided Difference Table
x F[ ] F[ , ] F[ , , ] xi f(xi)
0 -5 2 -4 0 -5
1 -3 6 1 -3
-1 -15 -1 -15
x F[ ] F[ , ] F[ , , ] xi yi
0 -5 2 -4 0 -5
1 -3 6
-1 -15 1 -3
-1 -15
3 (5)
2
1 0
f [ x1 ] f [ x0 ]
f [ x0 , x1 ]
x1 x0
Divided Difference Table
x F[ ] F[ , ] F[ , , ] xi yi
0 -5 2 -4 0 -5
1 -3 6
-1 -15 1 -3
-1 -15
15 (3)
6
1 1
f [ x2 ] f [ x1 ]
f [ x1 , x2 ]
x2 x1
Divided Difference Table
x F[ ] F[ , ] F[ , , ] xi yi
0 -5 2 -4 0 -5
1 -3 6
-1 -15 1 -3
-1 -15
6 (2)
4
1 (0)
f [ x1 , x2 ] f [ x0 , x1 ]
f [ x0 , x1 , x2 ]
x2 x0
Divided Difference Table
x F[ ] F[ , ] F[ , , ] xi yi
0 -5 2 -4 0 -5
1 -3 6
-1 -15 1 -3
-1 -15
f 2 ( x) 5 2( x 0) 4( x 0)( x 1)
x y x y
1 0 2 3
2 3 1 0
3 8 3 8
P2 ( x) 0 3( x 1) 1( x 1)( x 2) P2 ( x) 3 3( x 2) 1( x 2)( x 1)
x2 1 x2 1
f [ x0 , x1 , x2 ] f [ x1 , x2 , x0 ] f [ x2 , x1 , x0 ]
Example
• Find a polynomial to x f(x)
interpolate the data.
2 3
4 5
5 1
6 6
7 9
Example
x f(x) f[ , ] f[ , , ] f[ , , , ] f[ , , , , ]
2 3 1 -1.6667 1.5417 -0.6750
4 5 -4 4.5 -1.8333
5 1 5 -1
6 6 3
7 9
f 4 3 1( x 2) 1.6667( x 2)( x 4) 1.5417( x 2)( x 4)( x 5)
0.6750( x 2)( x 4)( x 5)( x 6)
Algoritmo computacional para el polinomio
de interpolación de Newton
Matlab Code:
function yint = Newtint(x,y,xx)
n = length(x);
if length(y)~=n
error('x and y must be same length');
end
b = zeros(n,n);
% assign dependent variables to the first column of b.
b(:,1) = y(:); % the (:) ensures that y is a column vector.
for j = 2:n
for i = 1:n-j+1
b(i,j) = (b(i+1,j-1)-b(i,j-1))/(x(i+j-1)-x(i));
end
end
% use the finite divided differences to interpolate
xt = 1;
yint = b(1,1);
for j = 1:n-1
xt = xt*(xx-x(j));
yint = yint+b(1,j+1)*xt;
end
Lagrange Interpolating Polynomials
Problem: xi x0 x1 …. xn
Given
yi y0 y1 …. yn
i j
Lagrange Interpolating Polynomials
n
f n ( x) Li ( x) f ( xi )
i 0
n x xj
Li ( x)
j 0 xi x j
j i
x x1 x x0
f1 ( x) f ( x0 ) f ( x1 )
x0 x1 x1 x0
Lo (x) L1 ( x)
Lagrange Interpolating Polynomials
• Second order version (n = 2):
f 2 ( x)
x x1 x x2
f ( x0 ) Lo ( x) , j 0
x0 x1 x0 x 2
x x0 x x2
f ( x1 ) L1 ( x) , j 1
x1 x0 x1 x 2
x x0 x x1
f ( x2 ) L2 ( x) , j 2
x2 x0 x2 x1
Lagrange Interpolating Polynomials -
Example
x0 1 f ( x0) ln(1) 0
x1 4 f ( x1) ln(4) 1.386294
x2 6 f ( x2) ln(6) 1.791760
Lagrange Interpolating Polynomials –
Example (cont’d)
• First order polynomial:
x x1 x x0
f 1( x) f ( x 0) f ( x1)
x0 x1 x1 x0
24 2 1
f 1(2) 0 1.386294 0.4620981
1 4 4 1
Lagrange Interpolating Polynomials –
Example (cont’d)
x x1 x x2 x 4 x 6
Lo ( x )
xo x1 xo x2 0 4 0 6
x xo x x2 x 0 x 6
L1 ( x )
x1 xo x1 x2 4 0 4 6
x xo x x1 x 0 x 4
L2 ( x )
x2 xo x2 x1 6 0 6 4
Lagrange Interpolating Polynomials –
Example (cont’d)
n n
x xj
f n ( x ) Li ( x ) f ( xi ) Li ( x ) ( j i)
i 0 j 0 xi x j
(2 4)(2 6)
f 2 (2) 0
(1 4)(1 6)
(2 1)(2 6)
1.386294
(4 1)(4 6)
(2 1)(2 4)
1.791760 0.5658444
(6 1)(6 4)
Lagrange Interpolating Polynomials –
Example (cont’d)
Pseudocode – Lagrange interpolation
Matlab Code:
function yint = Lagrange(x,y,xx)
n = length(x);
if length(y) ~= n
error('x and y must be same length');
end
s = 0;
for i = 1:n
product = y(i);
for j = 1:n
if i ~= j
product = product*(xx-x(j))/(x(i)-x(j));
end
end
s = s + product;
end
yint = s;
Summary
Next Class