Upload
mitali-dixit
View
219
Download
0
Embed Size (px)
Citation preview
8/11/2019 Comp Phys3
1/33
Interpolation, Extrapolation&
Polynomial Approximation
November 13, 2012
Interpolation, Extrapolation & Polynomial Approximation
http://find/8/11/2019 Comp Phys3
2/33
Introduction
In many cases we know the values of a function f (x ) at a set of pointsx 1, x 2, ..., x N , but we dont have the analytic expression of the functionthat lets us calculate its value at an arbitrary point. We will try toestimate f (x ) for arbitrary x by drawing a curve through the x i andsometimes beyond them.
The procedure of estimating the value of f (x ) for x [x 1, x N ] is calledinterpolation while if the value is for points x /[x 1, x N ] extrapolation.
The form of the function that approximates the set of points should be a
convenient one and should be applicable to a general class of problems.Interpolation, Extrapolation & Polynomial Approximation
http://find/8/11/2019 Comp Phys3
3/33
Polynomial Approximations
Polynomial functions are the most common ones while rational andtrigonometric functions are used quite frequently.
We will study the following methods for polynomial approximations:
Lagranges PolynomialHermite Polynomial
Taylor Polynomial
Cubic Splines
Interpolation, Extrapolation & Polynomial Approximation
http://find/8/11/2019 Comp Phys3
4/33
Lagrange Polynomial
Lets assume the following set of data:
x 0 x 1 x 2 x 3x 3.2 2.7 1.0 4.8f (x ) 22.0 17.8 14.2 38.3
f 0 f 1 f 2 f 3
Then the interpolating polynomial will be of 4th order i.e.
ax 3
+ bx 2
+ cx + d = P (x ). This leads to 4 equations for the 4 unknowncoefficients and by solving this system we get a = 0.5275, b = 6 .4952,c = 16.117 and d = 24.3499 and the polynomial is:
P (x ) = 0.5275x 3 + 6 .4952x 2 16.117x + 24 .3499
It is obvious that this procedure is quite laboureus and Lagrangedeveloped a direct way to nd the polynomial
P n (x ) = f 0L0(x ) + f 1L1(x ) + .... + f n Ln (x ) =n
i =0
f i Li (x ) (1)
where Li (x ) are the Lagrange coefficient poly no m ialsInterpolation, Extrapolation & Polynomial Approximation
http://goforward/http://find/http://goback/8/11/2019 Comp Phys3
5/33
L j (x ) = (x x 0)(x x 1)...(x x j 1)(x x j +1 )...(x x n )(x j x 0)(x j x 1)...(x j x j 1)(x j x j +1 )...(x j x n )
(2)
and obviously:L j (x k ) = jk =
0 if j = k 1 if j = k
where jk is Kroneckers symbol.
ERRORSThe error when the Lagrange polynomial is used to approximate acontinuous function f (x ) it is :
E (x ) = ( x x 0)(x x 1).... (x x n )f (n+1) ( )
(n + 1)!
where [x 0, x N ] (3)
NOTELagrange polynomial applies for evenly and unevenly spaced points. Stillif the points are evenly spaced then it reduces to a much simpler form.
Interpolation, Extrapolation & Polynomial Approximation
http://find/8/11/2019 Comp Phys3
6/33
Lagrange Polynomial : Example
Find the Lagrange polynomial thatapproximates the function y = cos( x ).We create the table
x i 0 0.5 1f i 1 0.0 -1
The Lagrange coeffiecient polynomials are:
L1(x ) = (x x 2)(x x 3)(x 1 x 2)(x 1 x 3)
= (x 0.5)(x 1)(0 0.5)(0 1)
= 2x 2 3x + 1 ,
L2(x ) = (x x 1) (x x 3)
(x 2 x 1)(x 2 x 3) =
(x 0)(x 1)(0.5 0)(0 .5 1)
= 4(x 2 x )
L3(x ) = (x x 1)(x x 2)(x 3 x 1)(x 3 x 2)
= (x 0)(x 0.5)(1 0)(1 0.5)
= 2x 2 x
thus
P (x ) = 1 (2x 2 3x + 1) 0.4 (x 2 x ) + ( 1) (2x 2 x ) = 2x + 1
Interpolation, Extrapolation & Polynomial Approximation
http://find/8/11/2019 Comp Phys3
7/33
The error will be:
E (x ) = x (x 0.5) (x 1)3 sin( )
3!
e.g. for x = 0 .25 is E (0.25) 0.24.
Interpolation, Extrapolation & Polynomial Approximation
http://find/8/11/2019 Comp Phys3
8/33
Newton Polynomial
Forward Newton-Gregory
P n (x s ) = f 0 + s f 0 + s (s 1)2! 2f 0 + s (s 1)( s 2)3!
3f 0 + ...
= f 0 + s 1 f 0 +
s 2
2f 0 + s 3
3f 0 + ...
=
n
i =0
s i
i
f 0 (4)
where x s = x 0 + s h and
f i = f i +1 f i (5)
2f i = f i +2 2f i +1 + f i (6)
3f i = f i +3 3f i +2 + 3 f i +1 f i (7)
n f i = f i + n nf i + n 1 + n(n 1)
2! f i + n 2
n(n 1)(n 2)3!
f i + n 3 + (8)
Interpolation, Extrapolation & Polynomial Approximation
http://find/8/11/2019 Comp Phys3
9/33
Newton Polynomial
ERROR The error is the same with the Lagrange polynomial :
E (x ) = ( x x 0)(x x 1).... (x x n )f (n+1) ( )
(n + 1)! where [x 0, x N ] (9)
x f (x ) f (x ) 2 f (x ) 3 f (x ) 4 f (x ) 5 f (x )0.0 0.000
0.2030.2 0.203 0.017
0.220 0.0240.4 0.423 0.041 0.020
0.261 0.044 0.0320.6 0.684 0.085 0.052
0.246 0.0960.8 1.030 0.181
0.5271.0 1.557
Table: Example of a difference matrix
Backward Newton-Gregory
P n (x ) = f 0+ s 1 f 1+
s + 12
2f 2+ ...+ s + n 1
n n f n
(10)Interpolation, Extrapolation & Polynomial Approximation
http://find/8/11/2019 Comp Phys3
10/33
x F (x ) f (x ) 2 f (x ) 3 f (x ) 4 f (x ) 5 f (x )0.2 1.06894
0.112420.5 1.18136 0.01183
0.12425 0.001230.8 1.30561 0.01306 0.00015
0.13731 0.00138 0.0000011.1 1.44292 0.01444 0.00014
0.15175 0.01521.4 1.59467 0.01596
0.167711.7 1.76238
Newton-Gregory forward with x 0 = 0 .5:
P 3(x ) = 1 .18136 + 0 .12425 s + 0 .01306 s 2 + 0 .00138
s 3
= 1 .18136 + 0 .12425 s + 0 .01306 s (s 1)/ 2 + 0 .00138 s (s 1) (s 2)/ 6= 0.9996 + 0 .3354 x + 0 .052 x 2 + 0 .085 x 3
Newton-Gregory backwards with x 0 = 1 .1:
P 3(x ) = 1 .44292 + 0 .13731 s + 0 .01306 s + 1
2 + 0 .00123 s + 2
3= 1 .44292 + 0 .13731 s + 0 .01306 s (s + 1) / 2 + 0 .00123 s (s + 1) ( s + 2) / 6= 0.99996 + 0 .33374 x + 0 .05433 x 2 + 0 .007593 x 3
Interpolation, Extrapolation & Polynomial Approximation
http://find/8/11/2019 Comp Phys3
11/33
Hermite Polynomial
This applies when we have information not only for the values of f (x )but also on its derivative f (x )
P 2n 1(x ) =n
i =1
Ai (x )f i +n
i =1
B i (x )f
i (11)
where
Ai (x ) = [1 2(x x i )Li (x i )] [Li (x )]2 (12)B i (x ) = ( x x i ) [Li (x )]2 (13)
and Li (x ) are the Lagrange coefficients.
ERROR : the accuracy is similar to that of Lagrange polynomial of order2n!
y (x ) p (x ) = y (2n+1) ( )(2n + 1)!
[(x x 1)(x x 2) . . . (x x n )]2 (14)
Interpolation, Extrapolation & Polynomial Approximation
l l l
http://find/http://goback/8/11/2019 Comp Phys3
12/33
Hermite Polynomial : Example
Fit a Hermite polynomial to thedata of the table:
k x k y k y k 0 0 0 01 4 2 0
The Lagrange coefficients are:
L0(x ) = x x 1
x 0 x 1=
x 40 4
= x 4
4 L1(x ) =
x x 0x 1 x 0
= x 4
L0(x ) = 1x 0 x 1 =
14 L1(x ) =
1x 1 x 0 =
14
ThusA0(x ) = 1 2 L0(x x 0) L
20 = 1 2
1
4(x 0)
x 4
4
2
A1(x ) = 1 2 L0(x x 1) L21 = 1 2
1
4(x 4)
x
4
2= 3
x
2
x
4
2
B 0(x ) = ( x 0) x 4
4
2= x
x 4
4
2B 1(x ) = ( x 4)
x
4
2
And the Hermite polynomial is:
P (x ) = (6 x )x 2
16.
Interpolation, Extrapolation & Polynomial Approximation
T l P l i l
http://find/8/11/2019 Comp Phys3
13/33
Taylor Polynomial
It is an alternative way of approximating functions with polynomials. Inthe previous two cases we found the polynomial P (x ) that gets the same
value with a function f (x ) at N points or the polynomial that agrees witha function and its derivative at N points. Taylor polynomial has the samevalue x 0 with the function but agrees also up to the Nth derivative withthe given function. That is:
P (i ) (x 0) = f (i ) (x 0) and i = 0 , 1,..., n
and the Taylor polynomial has the well known form from Calculus
P (x ) =N
i =0
f (i ) (x )i !
(x x 0)i (15)
ERROR : was also estimated in calculus
E N (x ) = ( x x 0)N +1f (N +1) ( )(N + 1)!
(16)
Interpolation, Extrapolation & Polynomial Approximation
T l P l i l E l
http://find/8/11/2019 Comp Phys3
14/33
Taylor Polynomial : Example
We will show that for the calculation of e = 2 .718281828459... with13-digit approximation we need 15 terms of the Taylor expansion.All the derivatives at x = 1 are:
y 0 = y (1)0 = y
(2)0 = ... = y
(n)0 = 1
thusp (x ) =
n
i =1
1i !
x n = 1 + x + x 2
2 + ... +
1n!
x n
and the error will be
|E n | = x n+1 e
(n + 1)! = e
16! < 3
16! = 1 .433 10 13
Interpolation, Extrapolation & Polynomial Approximation
http://find/8/11/2019 Comp Phys3
15/33
Interpolation ith C bic Splines
8/11/2019 Comp Phys3
16/33
Interpolation with Cubic Splines
Interpolation, Extrapolation & Polynomial Approximation
Interpolation with Cubic Splines
http://find/8/11/2019 Comp Phys3
17/33
Interpolation with Cubic Splines
Let the cubic for the i th interval, which lies between the points (x i , y i )and (x i +1 , y i +1 ) has the form:
y (x ) = ai (x x i )3 + b i (x x i )2 + c i (x x i ) + d i
Since it ts at the two endpoints of the interval:
y i = ai (x i x i )3
+ b i (x i x i )2
+ c i (x i x i ) + d i = d i y i +1 = ai (x i +1 x i )3 + b i (x i +1 x i )2 + c i (x i +1 x i ) + d i
= ai h3i + b i h2i + c i hi + d i
where hi = x i +1 x i . We need the 1st and 2nd derivatives to relate the
slopes and curvatures of the joining polynomials, by differentiation we gety (x ) = 3 ai (x x i )2 + 2 b i (x x i ) + c i y (x ) = 6 ai (x x i ) + 2 b i
Interpolation, Extrapolation & Polynomial Approximation
The mathematical procedure is simplied if we write the equations in
http://find/8/11/2019 Comp Phys3
18/33
The mathematical procedure is simplied if we write the equations interms of the 2nd derivatives of the interpolating cubics. Lets name S i the 2nd derivative at the point (x i , y i ) then we can easily get:
b i = S i 2 , ai =
S i +1 S i 6hi (17)
which means
y i +1 = S i +1 S i
6hi h3i +
S i 2
h2i + c i hi + y i
and nally
c i = y i +1 y i
hi
2hi S i + hi S i +16
(18)
Now we invoke the condition that the slopes of the two cubics joining at
(x i , y i ) are the same:y i = 3ai (x i x i )2 + 2 b i (x i x i ) + c i = c i y i = 3ai 1 (x i x i 1)2 + 2 b i 1 (x i x i 1) + c i 1
= 3 ai 1h2i 1 + 2b i 1hi 1 + c i 1
Interpolation, Extrapolation & Polynomial Approximation
http://find/8/11/2019 Comp Phys3
19/33
By equating these and substituting a, b , c and d we get:
y i = y i +1 y i
hi 2hi S i + hi S i +1
6
= 3S i S i 1
6hi 1h2i 1 + 2
S i 12
hi 1 + y i y i 1
hi 1
2hi 1S i 1 + hi 1S i 6
and by simplifying we get:
hi 1S i 1 + 2 ( hi 1 + hi ) S i + hi S i +1 = 6y i +1 y i
hi
y i y i 1hi 1
(19)
If we have n + 1 points the above relation can be applied to the n 1internal points. Thus we create a system of n 1 equations for the n + 1unknown S i . This system can be solved if we specify the values of S 0 andS n .
Interpolation, Extrapolation & Polynomial Approximation
The system of n 1 equations with n + 1 unknown will be written as:
http://find/8/11/2019 Comp Phys3
20/33
The system of n 1 equations with n + 1 unknown will be written as:.......
h0 2(h0 + h1) h1h1 2(h1 + h2) h2
h2 2(h2 + h3) h3....... .......
hn 2 2(hn 2 + hn 1 ) hn 1
S 0S 1S 2:S n 2S n 1S n
= 6
....y 2 y 1
h1 y 1 y 0
h0y 3 y 2
h2 y 2 y 1
h1....y n y n
1hn 1 y n
1 y n
2hn 2....
Y
From the solution of this linear systems we get the coefficients ai , b i , c i and d i via the relations:
ai = S i +1 S i 6hi , b i = S i 2
(20)
c i = y i +1 y i
hi
2hi S i + hi S i +16
(21)
d i = y i (22)
Interpolation, Extrapolation & Polynomial Approximation
http://find/8/11/2019 Comp Phys3
21/33
Choice I Take, S 0 = 0 and S n = 0 this will lead to the solution of thefollowing (n 1) (n 1) linear system:
2(h0 + h1) h1h1 2(h1 + h2) h2
h2 2(h2 + h3) h3....hn 2 2(hn 2 + hn 1)
S 1S 2S 3
S n 1
= Y
Choice II Take, S 0 = S 1 and S n = S n 1 this will lead to the solution of the following (n 1) (n 1) linear system:
3h0 + 2 h1 h1h1 2(h1 + h2) h2
h2 2(h2 + h3) h3... ...
hn 2 2hn 2 + 3 hn 1
S 1S 2S 3
S n 1
= Y
Interpolation, Extrapolation & Polynomial Approximation
http://find/8/11/2019 Comp Phys3
22/33
Choice III Use linear extrapolation
S 1 S 0h0= S 2 S 1h1
S 0 = (h0 + h1)S 1 h0S 2h1S n S n 1
hn 1=
S n 1 S n 2hn 2
s n = (hn 2 + hn 1)S n 1 hn 1S n 2
hn 2this will lead to the solution of the following (n 1) (n 1) linearsystem:
(h0+ h1)( h0 +2 h1)h1
h21 h20h1
h1 2(h1 + h2) h2h2 2(h2 + h3) h3
.... ....h2n 2
h2n 1hn 2
(hn 1+ hn 2)( hn 1+2 hn 2)
hn 2
S 1S 2S 3
S n 1
= Y
Interpolation, Extrapolation & Polynomial Approximation
http://find/8/11/2019 Comp Phys3
23/33
8/11/2019 Comp Phys3
24/33
8/11/2019 Comp Phys3
25/33
Condition III :
6 0 01 4 10 0 6
S 1S 2S 3
=3672108
S 0 = 0 S 1 = 6S 2 = 12 S 3 = 18S 4 = 24
Condition IV :
2 1 0 0 01 4 1 0 00 1 4 1 00 0 1 4 10 0 0 1 2
S 0S 1S 2S 3S 4
=
6367210866
S 0 = 0S 1 = 6S 2 = 12S 3 = 18S 4 = 24
Interpolation, Extrapolation & Polynomial Approximation
Interpolation with Cubic Splines : Problems
http://find/http://goback/8/11/2019 Comp Phys3
26/33
p p
1 The following data are from astronomical observations andrepresent variations of the apparent magnitude of a type of variablestars called Cepheids
Time 0.0 0.2 0.3 0.4 0.5 0.6 0.7 0.8 1.0Apparentmagnitude
0.302 0.185 0.106 0.093 0.24 0.579 0.561 0.468 0.302
Use splines to create a new table for the apparent magnitude forintervals of time of 0.5.
2 From the following table nd the acceleration of gravity atTubingen (48o 31) and the distance between two points withangular separation of 1 of a degree.
Latitude Length of 1 of arcon the parallel
local accelerationof gravity g
00 1855.4 m 9.7805 m/sec 2
150 1792.0 m 9.7839 m/sec 2
300 1608.2 m 9.7934 m/sec 2
450 1314.2 m 9.8063 m/sec 2
600 930.0 m 9.8192 m/sec 2
750 481.7 m 9.8287 m/sec 2
900 0.0 m 9.8322 m/sec 2
Interpolation, Extrapolation & Polynomial Approximation
Rational function approximations
http://find/http://goback/8/11/2019 Comp Phys3
27/33
pp
Here we introduce the notion of rational approximations for functions .We will constrain our discussion to the so called Pade approximation .A rational approximation of f (x ) on [a, b ], is the quotient of twopolynomials P n (x ) and Q m (x ) with degrees n and m1
f (x ) = R N (x ) P n (x )Q m (x )
= a0 + a1x + a2x 2 + ... + an x n
1 + b 1x + b 2x 2 + ... + b m x m , N = n + m
i.e. there are N + 1 = n + m + 1 constants to be determined.The method of Pade requires that f (x ) and its derivatives are continuousat x = 0 . This choice makes the manipulation simpler and a change of variable can be used to shift, if needed, the calculations over to aninterval that contains zero.We begin with the Maclaurin series for f (x ) (up to the term x N ), thiscan be written as :
f (x ) c 0 + c 1x + ... + c N x N
where c i = f ( i ) (0) / (i !).1
Sometimes we write R
N (x
) R
n, m (x
).Interpolation, Extrapolation & Polynomial Approximation
Pade approximation
http://find/http://goback/8/11/2019 Comp Phys3
28/33
pp
Then we create the difference
f (x ) R N (x ) c 0 + c 1x + ... + c N x N
a0 + a1x + ... + a n x n
1 + b 1x + ... + b m x m
=c 0 + c 1x + ... + c N x
N (1 + b 1x + ... + b m x m ) (a0 + a1x + ... + an x n )
1 + b 1
x + ... + b m
x m
If f (0) = R N (0) then c 0 a0 = 0 .In the same way , in order for the rst N derivatives of f (x ) and R N (x )to be equal at x = 0 the coefficients of the powers of x up to x N in thenumerator must be zero also.
Interpolation, Extrapolation & Polynomial Approximation
http://find/http://goback/8/11/2019 Comp Phys3
29/33
This gives additionally N equations for the as and b s
b 1c 0 + c 1 a1 = 0
b 2c 0 + b 1c 1 + c 2 a2 = 0b 3c 0 + b 2c 1 + b 1c 2 + c 3 a3 = 0
...b m c n m + b m 1c n m +1 + ... + c n an = 0
b m c n m +1 + b m 1c n m +2 + ... + c n+1 = 0 (23)b m c n m +2 + b m 1c n m +3 + ... + c n+2 = 0
...b m c N m + b m 1c N m +1 + ... + c N = 0
Notice that in each of the above equations, the sum of subscripts on thefactors of each product is the same, and is equal to the exponent of thex -term in the numerator.
Interpolation, Extrapolation & Polynomial Approximation
Pade approximation : Example
http://find/http://goback/8/11/2019 Comp Phys3
30/33
For the R 9(x ) or R 5,4(x ) Pade approximation for the function tan 1 (x )
we calculate the Maclaurin series of tan 1(x ):
tan 1 (x ) = x
1
3x 3 +
1
5x 5
1
7x 7 +
1
9x 9
and then
f (x ) R 9 (x ) =x 13 x
3 + 15 x 5 1
7 x 7 + 19 x
9 1 + b 1 x + b 2x 2 + b 3x 3 + b 4 x 4 a0 + a1x + a2x 2 + ... + a5x 5
1 + b 1x + b 2x 2 + b 3x 3 + b 4x 4
and the coefficients will be found by the following system of equations:
a0 = 0 , a1 = 1 , a2 = b 1 , a3 = 13
+ b 2 , a4 = 13
b 1 + b 3 , a5 = 15
13
b 2 + b 4
1
5b 1
1
2b 3 = 0 ,
1
7+
1
5b 2
1
3b 4 = 0 ,
1
7b 1 +
1
5b 3 = 0 ,
1
9
1
7b 2 +
1
5b 4 = 0 (24)
from which we geta0 = 0 , a1 = 1 , a2 = 0 , a3 = 79 , a4 = 0 , a5 =
64945 , b 1 = 0 , b 2 =
109 , b 3 = 0 , b 4 =
521 .
tan 1 x R 9(x ) = x + 79 x
3 + 64945 x 5
1 + 109 x 2 + 521 x 4
For x = 1 , exact 0.7854, R 9(1) = 0 .78558 while from the Maclaurinseries we get 0.8349!
Interpolation, Extrapolation & Polynomial Approximation
Rational approximation for sets of data
http://find/http://goback/8/11/2019 Comp Phys3
31/33
If instead of the analytic form of a function f (x ) we have a set of k points (x i , f (x i )) in order to nd a rational function R N (x ) such that for
every x i we will get f (x i ) = R N (x i ) i.e.
R N (x i ) = a0 + a1x i + a2x 2i + ... + an x
ni
1 + b 1x i + b 2x 2i + ... + b m x mi
= f (x i )
we will follow the approach used in constructing the approximatepolynomial. In other words the problem will be solved by nding thesolution of the following system of k m + n + 1 equations:
a0 + a1x 1 + ... + an x n1 (f 1x 1) b 1 ... (f 1x m1 ) b m = f 1
::
a0 + a1x i + ... + an x ni (f i x i ) b 1 ... (f i x
mi ) b m = f i ::
a0 + a1x k + ... + an x nk (f k x k ) b 1 ... (f k x mk ) b m = f k
i.e. we get k equations for the k unknowns a0, a1,..., an and b 1, b 2,..., b m .
Interpolation, Extrapolation & Polynomial Approximation
Rational approximation for sets of data : Example
http://find/http://goback/8/11/2019 Comp Phys3
32/33
We will nd the rational function approximations for the following set of data (-1,1), (0,2) and (1,-1).It is obvious that the sum of degrees of the polynomials in the nominatorand denominator must be (n + m + 1 3). Thus we can write:
R 1,1 (x ) = a0 + a1x 1 + b 1x
which leads to the following system
a0 + ( 1) a1 ( 1) b 1 = 1a0 + 0 a1 0 b 1 = 2a0 + 1 a1 ( 1) b 1 = 1
a0 = 2a1 = 1b 1 = 2
and the rational fuction will be:
R 1,1 (x ) = 2 x 1 2x .
Alternatively, one may derive the following rational function:
R 0,1 (x ) = a0
1 + b 1x + b 2x R (x ) =
21 2x x 2
Interpolation, Extrapolation & Polynomial Approximation
Rational approximation: Problems
http://find/http://goback/8/11/2019 Comp Phys3
33/33
1 Find the Pade approximation R 3,3(x ) for the function y = e x .Compare with the Maclaurin series for x = 1.
2 Find the Pade approximation R 3,5(x ) for the functions y = cos( x )and y = sin( x ). Compare with the Maclaurin series for x = 1.
3
Find the Pade approximation R 4,6(x ). for the functiony = 1 / x sin(x ). Compare with the Maclaurin series for x = 1.
4 Find the rational approximation for the following set of points:
0 1 2 4
0.83 1.06 1.25 4.15
Interpolation, Extrapolation & Polynomial Approximation
http://find/