Вы находитесь на странице: 1из 13

Interpolation

Numerical and Computing Methods (EP202)/


Numerical Methods (EP207)
What is Interpolation ?

Given (x0,y0), (x1,y1), …… (xn,yn), find the


value of ‘y’ at a value of ‘x’ that is not given.
Interpolants
Polynomials are the most common
choice of interpolants because they
are easy to:

Evaluate
Differentiate, and
Integrate.
Polynomial function

𝑓(𝑥) = 𝑏0 + 𝑏1 𝑥 + 𝑏2 𝑥 2 +. . . +𝑏𝑛 𝑥 𝑛
For n+1 data points, there is one and only one polynomial of order n that
passes through all the points.
Polynomial interpolation consists of determining the unique n-th order polynomial
that fits n+1 data points
This polynomial then provides a formula to compute intermediate values.

n=0 , 1 point
n=1, 2 point (linear eq)
n=2, 3 point (quad eq
n=3, 4 point (cubic eq
Newton’s Divided Difference Method

Linear interpolation n=1: Given (𝑥0 , 𝑦0 ), (𝑥1 , 𝑦1 ), pass a


linear interpolant through the data
𝑓𝑛(𝑥) = 𝑏0 + 𝑏1 𝑥 + 𝑏2 𝑥 2 +. . . +𝑏𝑛 𝑥 𝑛

𝑓1 (𝑥) = 𝑏0 + 𝑏1 (𝑥 − 𝑥0 )

Where
𝑏0 = 𝑓(𝑥0 )

f ( x1 ) − f ( x0 )
b1 =
x1 − x0
Example
⚫ Estimate the natural logarithm of 2 using linear interpolation(2
points, n=1). First, perform the computation by interpolating
between ln(1) and ln(6). Then, repeat the procedure, but use a
smaller interval from ln(1) to ln(4). For each case, calculate the
true percent relative error.
𝑓1 (2) = 0 + 0.4621(2 − 1)
𝑦 = ln 𝑥 =0.6932
x y Ea 𝑏0 = 𝑓 1 = 0
1 x0 0
f ( x1 ) − f ( x0 )
2 ? 0.3584 48.3% b1 =
6 x1 1.792 x1 − x0
x y Ea f ( x1 ) − f ( x0 )
b1 =
1 x0 0 x1 − x0
2 ? 0.4621 33.3%
𝑏1 = (1.3863 − 0) / (4-1) =0.4621
4 x1 1.3863
Quadratic Interpolation
Given ( x0 , y 0 ), ( x1 , y1 ), and ( x2 , y 2 ), fit a quadratic interpolant through the data.
𝑓2 (𝑥) = 𝑏0 + 𝑏1 (𝑥 − 𝑥0 ) + 𝑏2 (𝑥 − 𝑥0 )(𝑥 − 𝑥1 )

𝑏0 = 𝑓(𝑥0 )
𝑓(𝑥) = 𝑏0 + 𝑏1 𝑥 + 𝑏2 𝑥 2 +. . . +𝑏𝑛 𝑥 𝑛

𝑓(𝑥1 ) − 𝑓(𝑥0 )
𝑏1 =
𝑥1 − 𝑥0

𝑓(𝑥2 ) − 𝑓(𝑥1 ) 𝑓(𝑥1 ) − 𝑓(𝑥0 )


𝑥2 − 𝑥1 − 𝑥1 − 𝑥0
𝑏2 =
𝑥2 − 𝑥0
Example
⚫ Fit a second-order polynomial to the three points used in the
previous example (i.e. x0 = 0.5, x1 = 4, and x2 = 6).
⚫ Use the polynomial to evaluate ln(2) x=2 y=?.
𝑓2 (𝑥) = 𝑏0 + 𝑏1 (𝑥 − 𝑥0 ) + 𝑏2 (𝑥 − 𝑥0 )(𝑥 − 𝑥1 )
𝑓2 2 = −0.6931 + 0.5942 (2 − 0.5) + (−0. 07115)(2 − 0.5)(2 − 4)
=0.4116
𝑏0 = 𝑓(𝑥0 ) =-0.6931
𝑓2 3.5 = −0.6931 + 0.5942 (3.5 − 0.5) + (−0. 07115)(3.5 − 0.5)(3.5 − 4)
=
𝑓(𝑥1 )−𝑓(𝑥0 ) 1.386−(−0.6931)
𝑦 = ln 𝑥 =0.6932 𝑏1 = = =0.5942
𝑥1 −𝑥0 4−0.5

x y Ea
𝑓(𝑥2 )−𝑓(𝑥1 ) 𝑓(𝑥1 )−𝑓(𝑥0 )
0.5 x0 -0.6931 𝑥2 −𝑥1

𝑥1 −𝑥0
𝑏2 =
3.5 ? 1.1962 4.52% 𝑥2 −𝑥0

4 x1 1.386 =-0.07115
6 x2 1.792
General Form
𝑓2 (𝑥) = 𝑏0 + 𝑏1 (𝑥 − 𝑥0 ) + 𝑏2 (𝑥 − 𝑥0 )(𝑥 − 𝑥1 )

where
b0 = f [ x0 ] = f ( x0 )
f ( x1 ) − f ( x 0 )
b1 = f [ x1 , x0 ] =
x1 − x0
f ( x 2 ) − f ( x1 ) f ( x1 ) − f ( x0 )

f [ x 2 , x1 ] − f [ x1 , x0 ] x 2 − x1 x1 − x0
b2 = f [ x 2 , x1 , x0 ] = =
x 2 − x0 x 2 − x0

Rewriting
𝑓2 (𝑥) = 𝑓[𝑥0 ] + 𝑓[𝑥1 , 𝑥0 ](𝑥 − 𝑥0 ) + 𝑓[𝑥2 , 𝑥1 , 𝑥0 ](𝑥 − 𝑥0 )(𝑥 − 𝑥1 )
General Form
Given (n + 1) data points, (x0 , y0 ), (x1 , y1 ),......, (xn −1 , y n −1 ), (xn , y n ) as
f n ( x) = b0 + b1 ( x − x0 ) + .... + bn ( x − x0 )( x − x1 )...( x − xn−1 )
where
b0 = f [ x0 ]
b1 = f [ x1 , x 0 ]
n=0 , 1 point
b2 = f [ x2 , x1 , x0 ]
n=1, 2 point (linear eq)

n=2, 3 point (quad eq
bn −1 = f [ xn−1 , xn −2 ,...., x0 ] n=3, 4 point (cubic eq
bn = f [ xn , xn −1 ,...., x0 ]
General form

The third order polynomial, given ( x 0 , y 0 ), ( x1 , y1 ), ( x 2 , y 2 ), and ( x 3 , y 3 ), is

f 3 ( x) = f [ x0 ] + f [ x1 , x0 ]( x − x0 ) + f [ x 2 , x1 , x0 ]( x − x0 )( x − x1 )
+ f [ x3 , x 2 , x1 , x0 ]( x − x0 )( x − x1 )( x − x 2 )
b0
x0 f ( x0 ) b1
f [ x1 , x 0 ] b2
x1 f ( x1 ) f [ x 2 , x1 , x0 ] b3
f [ x 2 , x1 ] f [ x3 , x2 , x1 , x0 ]
x2 f ( x2 ) f [ x3 , x 2 , x1 ]
f [ x3 , x 2 ]
x3 f ( x3 )
𝑏3 = 𝑓[x3,x2,x1] – f [x2,x1,x0] / (x3-x0)
𝑏3 = [𝑓[x3,x2] – f[x2,x1] / (x3 –x1) ]–[ f [x2,x1,x0] ]/ (x3-x0)

𝑏3 = [𝑓[x3,x2] – f[x2,x1] / (x3 –x1) ] – [𝑓[x2,x1] – f[x1,x0] / (x2 –x0)] / (x3-x0)


Example

⚫ In the previous example, data points at


x0 = 0.5, x1 = 4, and x2 = 6 were used to
estimate ln(2) with a parabola. Now,
adding a fourth point (x3 = 5), estimate
ln(2) with a third-order Newton’s
interpolating polynomial. F(x)= ln x
𝑓3 𝑥 = 𝑓[𝑥0 ] + 𝑓[𝑥1 , 𝑥0 ] 𝑥 − 𝑥0 + 𝑓[𝑥2 , 𝑥1 , 𝑥0 ] 𝑥 − 𝑥0 𝑥 − 𝑥1 + 𝑓[𝑥3, 𝑥2 , 𝑥1 , 𝑥0 ] 𝑥 − 𝑥0 𝑥 − 𝑥1 (𝑥 − 𝑥2)

𝑓 4 − 𝑓(0.5) 𝑓 𝑥2 , 𝑥1 − 𝑓[𝑥1 , 𝑥0 ] 𝑓 𝑥3, 𝑥2 , 𝑥1 − 𝑓 𝑥2, 𝑥1 , 𝑥0


𝑓3 𝑥 = 𝑓[0.5] + 𝑥 − 𝑥0 + 𝑥 − 𝑥0 𝑥 − 𝑥1 + 𝑥 − 𝑥0 𝑥 − 𝑥1 (𝑥 − 𝑥2)
4 − 0.5 𝑥2 − 𝑥0 𝑥3 − 𝑥0

𝑓 6 − 𝑓(4) 𝑓 4 − 𝑓(0.5)
𝑓 4 − 𝑓(0.5) − 𝑓 𝑥3, 𝑥2 , 𝑥1 − 𝑓 𝑥2, 𝑥1 , 𝑥0
𝑓3 𝑥 = 𝑓[0.5] + 𝑥 − 𝑥0 + 6−4 4 − 0.5 𝑥 − 𝑥0 𝑥 − 𝑥1 + 𝑥 − 𝑥0 𝑥 − 𝑥1 (𝑥 − 𝑥2)
4 − 0.5 𝑥2 − 𝑥0 𝑥3 − 𝑥0
f 3 ( x) = f [ x0 ] + f [ x1 , x0 ]( x − x0 ) + f [ x 2 , x1 , x0 ]( x − x0 )( x − x1 )
+ f [ x3 , x 2 , x1 , x0 ]( x − x0 )( x − x1 )( x − x 2 )

f3 𝑥 = −0.6931 + 0.5941 1.5 + −0.0712 1.5 −2 + 0.0113 1.5 −2 (−4)


f3 𝑥 = −0.6931 + 0.8912 + 0.2136 + 0.1356 = 0.5473
b0 = f [ x0 ] = 𝑓 𝑥0 = −0.6931
x0 = 0.5, x1 = 4, x2 = 6, x3 =5
𝑓 𝑥1 − 𝑓(𝑥0) 𝑓 4 −𝑓(0.5)
b1 = f [ x1 , x 0 ] =
𝑥1 − 𝑥0
=
4−0.5
= 0.5941
𝑓 𝑥2 − 𝑓(𝑥1) 𝑓 𝑥1 − 𝑓(𝑥0)
𝑓[𝑥2, 𝑥1] − 𝑓[𝑥1, 𝑥0]
b2 = f [ x2 , x1 , x0 ] = = 𝑥2 − 𝑥1 − 𝑥1 − 𝑥0
𝑥2 − 𝑥0 𝑥2 − 𝑥0

0.2027−0.5941
𝑏3 = 𝑓[𝑥3, 𝑥2, 𝑥1, 𝑥0] = 𝑓[𝑥3, 𝑥2, 𝑥1] − 𝑓[𝑥2, 𝑥1, 𝑥0] 5.5
=-0.0712
𝑥3 − 𝑥0

𝑓 𝑥3 − 𝑓(𝑥2) 𝑓 𝑥2 − 𝑓(𝑥1) 𝑓 𝑥2 − 𝑓(𝑥1) 𝑓 𝑥1 − 𝑓(𝑥0)


− −
𝑥3 − 𝑥2 𝑥2 − 𝑥 1 − 𝑥2 − 𝑥1 𝑥1 − 𝑥0
= 𝑥3 − 𝑥1 𝑥 2 − 𝑥0
𝑥3 − 𝑥0
0.1823 − 0.2027 0.2027 − 0.5941
1 −
= 5.5 =0.0113

Вам также может понравиться