Professional Documents
Culture Documents
Polynomial Interpolation
Interpolation & Extrapolation
f x a1 a2 x a3 x ... an x
2 n 1
n 1 n 2
f ( x ) p1 x p2 x pn 1 x pn
Interpolating Polynomials
Similar triangles
f1 ( x ) f ( x1 ) f ( x 2 ) f ( x1 )
x x1 x 2 x1
f ( x 2 ) f ( x1 )
f1 ( x ) f ( x1 ) ( x x1 )
x 2 x1
Newton Linear Interpolation
Newton linear interpolation formula
f x 2 f x1
f1 x f x1 x x1
x 2 x1
Example 1: interpolate e2 using e1 and e5
e5 e1
f1 2 e 1
2 1 2.7183 148.41 2.7183 1 36.423
51 4
Exact e 7.3891 2
Newton Linear Interpolation
Accuracy of Interpolation
Logarithmic function
Linear estimates
of ln(2)
f 2 x b1 b2 x x1 b3 x x1 x x2
a1 b1 b2 x1 b3 x1 x 2
where a2 b2 b3 x1 b3 x 2
a b
3 3
Quadratic Interpolation
f 2 x b1 b2 x x1 b3 x x1 x x2
To get the coefficients b’s
1) Set x = x1, get b1 = f(x1)
f 2 x1 b1 b2 x1 x1 b3 x1 x1 x1 x2 b1 f x1
Exact e 7.3891
2
Example – use different xi
Example: interpolate e2 using e1, e1.5, and e2.5
x1 1 f x1 2.7183
x 2 1.5 f x 2 4.4817
x 2.5 f x 3 12.1825
3
e 2.5 e 1.5 e 1.5 e 1
e 1.5 e 1
b1 2.7183 ; b2 3.5268 ; b3 2.5 1.5 1.5 1 2.7827
1.5 1 2.5 1
Exact e 7.3891
2
Quadratic Interpolation
Quadratic Interpolation
Order of Interpolation
Linear, quadratic and cubic estimates of ln(2)
Logarithmic function
b1 f x1
b2 f x 2 , x1
b3 f x 3 , x 2 , x1
bn f x n , x n1 , , x 2 , x1
f x i , x j f x j , x k
f x i , x j , x k
xi xk
The difference of two finite differences
Newton’s Divided Differences
An iterative procedure
1. Evaluate all first-order finite differences; save f (x1) for b1
2. Evaluate second-order from firsts; save f [x2, x1] for b2
3. Continue to nth-order, saving needed ones
Newton Interpolation
f n 1 ( x ) b1 b2 ( x x 1 ) b3 ( x x 1 )( x x 2 ) bn ( x x 1 ) ( x x n 1 )
b1 f ( x 1 ) f x 1
f x 2 f x 1
b2 f x 2 , x 1
x 2 x1
f x 3 , x 2 f x 2 , x 1
b3 f x 3 , x 2 , x 1
x 3 x1
f x 4 , x 3 , x 2 f x 3 , x 2 , x 1
b4 f x 4 , x 3 , x 2 , x 1
x4 x1
f x 5 , x 4 , x 3 , x 2 f x 4 , x 3 , x 2 , x 1
b5 f x5 , x 4 , x 3 , x 2 , x 1
x5 x 1
x n x1
n 1
i xi yi f ( x i ) f x i 1 , x i f x i 2 , x i 1 , x i f x i 3 , , x i f x i 4 , , x i
First Second Third Fourth
1 x1 f ( x1 ) f x 2 , x 1 f x 3 , x 2 , x 1 f x 4 , x 3 , x 2 , x 1 f x 5 , x 4 , x 3 , x 2 , x 1
2 x2 f ( x2 ) f x 3 , x 2 f x 4 , x 3 , x 2 f x 5 , x 4 , x 3 , x 2 f x6 , x 5 , x 4 , x 3 , x 2
3 x3 f ( x3 ) f x 4 , x 3 f x 5 , x 4 , x 3 f x6 , x 5 , x 4 , x 3
4 x4 f ( x4 ) f x 5 , x 4 f x6 , x 5 , x 4
5 x5 f ( x5 ) f x6 , x 5
6 x6 f ( x6 ) Use the top element of each column
(= bn) to evaluate the interpolated
functional value f(x)
Percentage Relative Error
f(x) = ex,
Interpolation at [0 1 4 3 1.5 2.5]
Lagrange Interpolating Polynomials
( x x1 )( x x 2 ) ( x x i 1 )( x x i 1 ) ( x x n )
( x i x1 )( x i x 2 ) ( x i x i 1 )( x i x i 1 ) ( x k x n )
Pi ( x i )
j i ; Li ( x i ) P ( x ) 1
Note : i i Li ( x j ) ij
j i ; L (x ) 0
i j
Lagrange Interpolation
1st-order Lagrange polynomial
x x2 x x1
f1 ( x ) L1 f ( x1 ) L2 ( x ) f ( x 2 ) f ( x1 ) f ( x2 )
x1 x 2 x 2 x1
Second-order Lagrange polynomial
( x x2 )( x x3 ) ( x x1 )( x x3 ) ( x x1 )( x x2 )
f2 ( x ) f ( x1 ) f ( x2 ) f ( x3 )
( x1 x2 )( x1 x3 ) ( x2 x1 )( x2 x3 ) ( x3 x1 )( x3 x2 )
x1 x2 x3
L2(x)f(x2)
First-order Lagrange interpolation
f(x) = ex
Interpolation at [0 4]
Second-order Lagrange interpolation
f(x) = ex,
Interpolation at [0 1 4]
Third-order Lagrange interpolation
f(x) = ex,
Interpolation at [0 1 4 3]
Example: Lagrange Interpolation
Estimate f(x) = exp(x) at x = 2 using (x0, x1, x2, x3 ) = (0,1,4,3)
second-order: (x1, x2, x3 ) = (0,1,4)
( x 1)( x 4 ) ( x 0 )( x 4 ) ( x 0 )( x 1)
f2 ( x ) f (0 ) f ( 1) f (4 )
(0 1)( 0 4 ) ( 1 0 )( 1 4 ) ( 4 0 )( 4 1)
( 2 1)( 2 4 ) ( 2 0 )( 2 4 ) ( 2 0 )( 2 1)
f2 ( 2) ( 1.0 ) ( 1.71828 ) (54.5982 ) 12.224067
(0 1)( 0 4 ) ( 1 0 )( 1 4 ) ( 4 0 )( 4 1)
Runge’s
function
1
f(x)
1 25 x 2
Oscillations
1
f(x)
1 25 x 2
MATLAB Functions:
polyfit and polyval
>> x = linspace(-1,1,5); y = 1./(1+25*x.^2)
>> xx = linspace(-1,1); p = polyfit(x,y,4)
p =
3.3156 0.0000
>> y4 = polyval(p,xx);
-4.2772 0.0000 1.0000 4th-order polynomial
>> yr = 1./(1+25*xx.^2);
>> H=plot(x,y,'o',xx,y4,xx,yr,'--')
>> x=linspace(-1,1,11); y = 1./(1+25*x.^2)
y =
Columns 1 through 8
0.0385 0.0588 0.1000 0.2000 0.5000 1.0000 0.5000 0.2000
Columns 9 through 11
0.1000 0.0588 0.0385
>> p = polyfit(x,y,10)
p = 10th-order polynomial
Columns 1 through 8
-220.9417 0.0000 494.9095 -0.0000 -381.4338 0.0000 123.3597 -0.0000
Columns 9 through 11
-16.8552 0.0000 1.0000
>> y10 = polyval(p,xx);
>> H = plot(x,y,'o',xx,y10,xx,yr,'--')
>> set(H,'LineWidth',3,'MarkerSize',12)
>> print -djpeg Fig14_13.jpg
Runge’s Function with polynomial fit
4th-order 10th-order
Noisy straight line