Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
41 views

Lec 2

Uploaded by

hsyffwfwhsusg
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
41 views

Lec 2

Uploaded by

hsyffwfwhsusg
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

Interpolation and Approximation

What is interpolation?
Many times, data is given only at discrete points such as (x1, y1), (x2, y2),………. (xn, yn),
(xn+1, yn+1). So, how then does one find the value of y at any other value of x?
Well, a continuous function f(x) may be used to represent the n+1 data values with f(x)
passing through the n+1 point (Figure 2.1). Then we can find the value of y at any other
value of x. This is called interpolation.
Of course, if x falls outside the range of x for which the data is given, it is no longer
interpolation, but instead, is called extrapolation.
y

x3 , y3 

x1, y1 

f x 
x2 , y2 
x0 , y0 
x

Figure 2.1 Interpolation of discrete data

For n+1 data points, there is one and only one polynomial of order n that passes
through all the points. For example, there is only one straight line (that is, a
first-order polynomial) that connects two points. Similarly, only one parabola
connects a set of three 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.
One of the methods used to find this polynomial is called the Lagrange method of
interpolation. Other methods include Newton’s divided difference polynomial method
and the direct method.

Numerical Analysis /Lec. 2 -5-


Third Class
2.1 Lagrange Interpolating Polynomial
Consider a function f(x) that passes through the two distinct points (x0, f(x0)) and (x1,
f(x1)) as shown in Figure 2.2. The first order polynomial that approximates the
function between these two points can be expressed as
f(x) = a + bx
Where a and b are constants. f(x) can also be written in Lagrangian form as
f(x) = c0(x  x1) + c1(x  x0)
f(x1) f(x2)

f(x) f(x)
f(x1)

f(x0) f(x0)

x0 x1 x x0 x1 x2 x
Figure 2.2 First and second order polynomial approximation.

I. Linear
By weighting the average of the two values used to produce the coordinates of the
line the formula:
x  x2 x  x1
f1 ( x)  L1 f x1   L2 f x2  where: L1  L2 
x1  x 2 x 2  x1
Example 2.1
Compute a 4-decimal place value of ln 9.2 from ln 9.0 = 2.1972, ln 9.5 = 2.2513 by
linear Lagrange interpolation and determine the error, using the exact value of ln 9.2
= 2.2192.
Solution:
x1 = 9.0 , x2 = 9.5 , f1 = ln 9.0= 2.1972 , f2 = ln 9.5= 2.2513 ; hence we get
x  9.5
L1 ( x)   2.0( x  9.5), L1 (9.2)  2.0(0.3)  0.6
 0.5
x  9.0
L2 ( x)   2.0( x  9.0), L2 (9.2)  2  0.2  0.4
0.5
ln 9.2  p1 (9.2) = L1 (9.2)f1 + L2 (9.2)f2 = 0.6×2.1972 + 0.4×2.2513 = 2.2188
The absolute error is 2.2192 - 2.2188 = 0.0004

Numerical Analysis /Lec. 2 -6-


Third Class
II. Quadratic
By weighting the average of the three points that produce the parabola we can derive
the formula:
f 2 ( x)  L1 f x1   L2 f x2   L3 f x3 
where:
( x  x2 )( x  x3 ) ( x  x1 )( x  x3 ) ( x  x1 )( x  x2 )
L1  L2  L3 
( x1  x2 )( x1  x3 ) ( x2  x1 )( x2  x3 ) ( x3  x1 )( x.3  x2 )
Example 2.2
Compute ln 9.2 from the data in the previous example 2.1 and the additional third
value ln 11.0 = 2.3979.
Solution:
( x  9.5)( x  11.0)
L1 ( x )   x 2  20.5x  104.5  L1 (9.2)  0.5400
(9.0  9.5)(9.0  11.0)
( x  9.0)( x  11.0) 1
L 2 (x)   ( x 2  20x  99)  L 2 (9.2)  0.4800
(9.5  9.0)(9.5  11.0) 0.75
( x  9.0)( x  9.5) 1
L3 (x)   ( x 2  18.5x  85.5)  L 3 (9.2)  0.0200
(11.0  9.0)(11.0  9.5) 3

ln 9.2  p2(9.2) = 0.5400 × 2.1972 + 0.4800 ×2.2513  0.0200×2.3979 = 2.2192.


The absolute error is 2.2192 - 2.2192 = 0.0000

III. General Lagrange Interpolating Polynomial


In general, the Lagrange polynomial can be represented as:
n n x  xj
f n1 ( x)   Li ( x) f ( xi ) where Li ( x)  
i 1 j 1 xi  x j
j i

Example 2.3
Find the Lagrange interpolation polynomial that takes the values prescribed below
xk 0 1 2 4
f(xk) 1 1 2 5
Solution
3
P3(x) = L
k 0
3,k ( x ) f(xk)

( x  1)( x  2)( x  4) ( x  0)( x  2)( x  4)


P3(x) = (1) + (1)
(0  1)(0  2)(0  4) (1  0)(1  2)(1  4)
( x  0)( x  1)( x  4) ( x  0)( x  1)( x  2)
+ (2) + (5)
(2  0)( 2  1)( 2  4) (4  0)( 4  1)( 4  2)

Numerical Analysis /Lec. 2 -7-


Third Class
When working with grids having large numbers of intervals one typically assigns a
set of low degree (n = 1, 2, or 3) basis functions to each adjacent set of n+1 = 2, 3, or
4 nodes.

Example 2.4
The following table gives the value of density of saturated water for various
temperatures of saturated stream.
Temp oC ( = T) 100 150 200 250
Density kg/m3 (= d) 958 917 865 799
1) Use third order Lagrange interpolating polynomials to correlate density as a
function of temperature.
2) Find the densities when the temperatures are 130oC .
Solution
(T  150)(T  200)(T  250)
L1   - 1.3333 10-6 T 3 + 4  10-3 T 2 - 0.1566T + 10
(100  150)(100  200)(100  250)
(T  100)(T  200)(T  250)
L2   4  10-6 T 3 - 2.2  10-3 T 2  0.38T - 20
(150  100)(150  200)(150  250)
(T  100)(T  150)(T  250)
L3   - 4  10-6 T 3 + 2  10-3 T 2 - 0.31T + 15
(200  100)(200  150)(200  250)
(T  100)(T  150)(T  200)
L4   1.3333  10-6 T 3 + 6 10-4 T 2 - 0.08666 - 4
(250  100)(250  150)(250  200)

f 4 (x)  L1f (x1 )  L2f (x 2 )  L3f (x 3 )  L4f (x 4 )  - 4 10-6 T3 - 4 10-4 T 2 - 0.53T  1019

f 4 (130)  934.5520

Example 2.5
Use Lagrange global interpolation by one polynomial and piecewise polynomial
interpolation with quadratic for the following nodes.
xk 0 1 2 4 5
f(xk) 0 16 48 88 0
Solution
4
Global interpolation by one polynomial: P(x) = L
k 0
4 ,k ( x ) f(xk)

( x  1)(x  2)(x  4)(x  5) ( x  0)(x  2)(x  4)(x  5)


P4(x) = (0) + (16)
(0  1)(0  2)(0  4)(0  5) (1  0)(1  2)(1  4)(1  5)
( x  0)(x  1)(x  4)(x  5) ( x  0)(x  1)(x  2)(x  5)
+ (48) + (88) + 0
(2  0)(2  1)(2  4)(2  5) (4  0)(4  1)(4  3)(4  5)
 - 4.6667x 4 + 33.33x 3 - 59.3333x 2 + 46.6667x
Numerical Analysis /Lec. 2 -8-
Third Class
Piecewise polynomial interpolation with quadratic
( x  1)( x  2) ( x  0)( x  2) ( x  0)( x  1)
P2(x) = (0) + (16) + (48); 0x2
(0  1)(0  2) (1  0)(1  2) (2  0)( 2  1)
 8x  8x 2
( x  4)( x  5) ( x  2)( x  5) ( x  2)( x  4)
P2(x) = (48) + (88) + (0); 2x5
(2  4)( 2  5) (4  2)( 4  5) (5  2)(5  4)

 - 280 + 236x - 36x 2

2.1 Newton Divided Difference Interpolating


The Lagrangian interpolation polynomials are useful in discussions on numerical
integration. An alternative in interpolation is ‘Newton’s Divided Difference
Interpolation’. It involves fewer arithmetical operations.
Another advantage of Newton’s rests with the following scenario. Suppose we need to
improve the accuracy and increase the number of grid points. From the forms of
Lagrange interpolation polynomials, all the terms have to be evaluated once again,
and this is a huge amount of work if the number of points is large. Newton’s does not
suffer from this drawback, and just one additional term needs to be computed.

I. Linear Interpolation
Consider the diagram below in which a curve is modeled (poorly) by x1 x2 :

Using similar triangles the slopes are the same and hence:
f1 ( x)  f ( x1 ) f ( x2 )  f ( x1 )

x  x1 x2  x1

Numerical Analysis /Lec. 2 -9-


Third Class
And thus the coordinate on the curve at x1 can be approximated by rearranging the
above to become:
f ( x2 )  f ( x1 )
f1 ( x)  f ( x1 )  ( x  x1 )
x2  x1

Example 2.6
Estimate the common logarithm of 10 using linear Newton’s interpolation.
(a) Interpolate between log 8 = 0.9030900 and log 12 = 1.0791812.
(b) Interpolate between log 9 = 0.9542425 and log 11 = 1.0413927.
For each of the interpolations, compute the percent relative error based on the true
value.
Solution
1.0791812 0.90309
a) f1 (10)  0.90309 (10  8)  0.991136
12  8
1  0.991136
t   100%  0.886%
1
1.0413927 0.9542425
b) f1 (10)  0.9542425 (10  9)  0.997818
11  9
1  0.997818
t   100%  0.218%
1

II. Quadratic Interpolation


To reduce the error, a quadratic interpolation that introduces some curvature into the
interpolation is used. The form:
f 2 ( x)  b1  b2 ( x  x1 )  b3 ( x  x1 )( x  x2 )
Let x = x1 to produce:
b1  f ( x1 )
Let x = x2 and use the previous identity to produce:
f ( x 2 )  f ( x1 )
f ( x 2 )  f ( x1 )  b 2 ( x 2  x1 )  b3 ( x  x1 )(x  x 2 )  b 2 
x 2  x1
And again by substitution of b1 and b2 we derive that:
f ( x 3 )  f ( x 2 ) f ( x 2 )  f ( x1 )

f ( x 2 )  f ( x1 ) x3  x 2 x 2  x1
f ( x 3 )  f ( x1 )  ( x 3  x1 )  b3 ( x 3  x1 )(x 3  x 2 )  b3 
x 2  x1 x 3  x1

f ( x3 )  f ( x2 ) f ( x2 )  f ( x1 )

f ( x2 )  f ( x1 ) x3  x2 x2  x1
f 2 ( x)  f ( x1 )  ( x  x1 )  ( x  x1 )( x  x2 )
x2  x1 x3  x1

Numerical Analysis /Lec. 2 - 10 -


Third Class
Example 2.7
Fit a second-order Newton’s Interpolating polynomial to estimate log 10 using the
data from Example 2.7 at x = 8, 9, and 11. Compute the true percent relative error.
Solution
First, order the points
x1 = 9 f(x1) = 0.9542425
x2 = 11 f(x2) = 1.0413927
x3 = 8 f(x3) = 0.9030900
b1 = 0.9542425
1.0413927  0.9542425
b2   0.0435751
11  9
0.9030900  1.0413927
 0.0435751
8  11 0.0461009  0.0435751
b3    0.0025258
89 89
Substituting these values yields the quadratic formula
f 2 ( x)  0.9542425  0.0435751( x  9)  0.0025258( x  9)( x  11)
which can be evaluated at x = 10 for
f 2 (10)  0.9542425  0.0435751(10  9)  0.0025258(10  9)(10  11)  1.0003434
1  1.0003434
t   100%  0.03434%
1

III. General form of Newton Divided Difference Interpolating Polynomial


In general, if we find the finite differences defined as:
f (x i )  f (x j )
f [x i , x j ] 
xi  x j
f [x i , x j ]  f [x j , x k ]
f [x i , x j , x k ] 
xi  xk

f [ x n , x n 1 ,..., x 2 ]  f [ x n 1 , x n 2 ,..., x1 ]
f [ x n , x n 1 ,..., x1 ] 
x n  x1
Then the general Newton Interpolating Polynomial of order n – 1with n data points is
defined as:

f n 1 ( x)  b1  b2 ( x  x1 )  b3 ( x  x1 )( x  x2 )  ....  bn ( x  x1 )( x  x2 )...( x  xn 1 )

Numerical Analysis /Lec. 2 - 11 -


Third Class
b1  f ( x1 )
b2  f [ x 2 , x1 ]
Where b3  f [ x3 , x 2 , x1 ]

bn  f [ x n , x n 1 ,..., x1 ]

b0
x0 f ( x0 ) b1
f [ x1 , x0 ] b2
x1 f ( x1 ) f [ x2 , x1 , x0 ] b3
f [ x2 , x1 ] f [ x3 , x2 , x1 , x0 ]
x2 f ( x2 ) f [ x3 , x2 , x1 ]
f [ x3 , x 2 ]
x3 f ( x3 )

For an example of a third order polynomial, given ( x0 , y0 ), ( x1 , y1 ), ( x2 , y 2 ), and ( x3 , y3 ),

f 3 ( x)  f [ x0 ]  f [ x1 , x0 ]( x  x0 )  f [ x2 , x1 , x0 ]( x  x0 )( x  x1 )
 f [ x3 , x2 , x1 , x0 ]( x  x0 )( x  x1 )( x  x2 )

Example 2.8
The following table gives the value of density of saturated water for various temperatures of saturated
stream.
Tempo C ( = T) : 100 150 200 250 300
Density kg/m3 (= d) : 958 917 865 799 712
Using Newton divided difference interpolating find the densities when the temperatures are
130oC and 275oC respectively.
Solution
i T D f[xi+1,xi] f[xi+2,xi+1,xi] f[xi+3,xi+2,xi+1,xi] f[xi+4,xi+3,xi+2,xi+1,xi]
1 100 958
-0.8200
2 150 917 -0.0022
-1.0400 -4×10-6
3 200 865 -0.0028 -2.6667×10-8
-1.3200 -9.333×10-6
4 250 799 -0.0042
-1.7400
5 300 712
Numerical Analysis /Lec. 2 - 12 -
Third Class
P4 = 958 - 0.8200  (T - 100) - 0.0022  (T - 100) * (T - 150) - 4 10-6  (T - 100) * (T - 150) * (T - 200)
- 2.6667 10-8  (T - 100) * (T - 150) * (T - 200) * (T - 250)

P4 = 999 - 0.0167T - 0.0051T 2  1.4667 10-5 T 3 - 2.6667 10-8 T 4

P4 (130)  934.6864 kg/m3

P4 (275)  758.7187 kg/m3

Or by direct substitution
P4 (130)  934.6864 kg/m3

P(130)= 958-0.82×(130-100)-0.0022×(130-100)×(130-150) -4×10-6×(130-100) ×


(130-150) ×(130-200) -2.6667×10-8×(130-100) ×(130-150)×(130-200) ×(130-250)
= 934.6864 kg/m3

P(275)=958-0.82×(275-100)-0.0022×(275-100)×(275-150)-4×10-6×(275-100)
×(275-150) ×(275-200) -2.6667×10-8 ×(275-100)×(275-150)×(275-200) ×(275-250)
= 758.7188 kg/m3

Numerical Analysis /Lec. 2 - 13 -


Third Class

You might also like