Upload
others
View
28
Download
0
Embed Size (px)
Citation preview
Interpolation - IntroductionEstimation of intermediate values betweenprecise data points. The most common method ispolynomial interpolation:
Polynomial interpolation is used when the pointdetermined are very precise. The curverepresenting the behavior has to pass throughevery point (has to touch).
There is one and only one nth-order polynomialthat fits n+1 points
f ( x )=a0+a1 x+a2 x2+⋯ +an x n
Introduction
First order (linear) 3rd order (cubic)2nd order (quadratic)
n = 2 n = 3 n = 4
3
Interpolation
Polynomials are the most commonchoice of interpolation because theyare easy to:
EvaluateDifferentiate, andIntegrate.
Introduction
There are a variety of mathematical formats in which thispolynomial can be expressed:
The Newton polynomial (sec. 18.1)
The Lagrange polynomial (sec. 18.2)
5
Newton’s Divided-DifferenceInterpolating PolynomialsLinear Interpolation/
Is the simplest form of interpolation, connecting two data pointswith a straight line.
f1(x) designates that this is a first-order interpolating polynomial.
)()()(
)()(
)()()()(
001
0101
01
01
0
01
xxxx
xfxfxfxf
xx
xfxf
xx
xfxf
−−−+=
−−=
−−
Linear-interpolationformula
Slope and afinite divideddifferenceapproximation to1st derivative
6
Figure
18.2
7
Quadratic Interpolation/
If three data points are available, the estimate is improvedby introducing some curvature into the line connectingthe points.
A simple procedure can be used to determine the valuesof the coefficients.
))(()()( 1020102 xxxxbxxbbxf −−+−+=
02
01
01
12
12
22
01
0111
000
)()()()(
)()(
)(
xx
xx
xfxf
xx
xfxf
bxx
xx
xfxfbxx
xfbxx
−−−−
−−
==
−−==
==
8
General Form of Newton’s Interpolating Polynomials/
0
02111011
011
0122
011
00
01110
012100100
],,,[],,,[],,,,[
],[],[],,[
)()(],[
],,,,[
],,[
],[
)(
],,,[)())((
],,[))((],[)()()(
xx
xxxfxxxfxxxxf
xx
xxfxxfxxxf
xx
xfxfxxf
xxxxfb
xxxfb
xxfb
xfb
xxxfxxxxxx
xxxfxxxxxxfxxxfxf
n
nnnnnn
ki
kjjikji
ji
jiji
nnn
nnn
n
−−=
−−
=
−−
=
=
===
−−−++−−+−+=
−−−−
−
−−
Bracketed functionevaluations are finitedivided differences
Lagrange Interpolating Polynomials
The general form for n+1 data points is:
∏
∑
≠=
=
−−
=
=
n
ijj ji
ji
n
iiin
xx
xxxL
xfxLxf
0
0
)(
)()()(
designates the “product of”
Lagrange Interpolating Polynomials
f 1( x )=x− x1
x0− x1
f ( x0 )+x− x0
x1− x0
f ( x1 )
• Linear version (n = 1):Used for 2 points of data: (xo,f(xo)) and (x1,f(x1)),
Lo( x ) L1 ( x )
Lagrange InterpolatingPolynomials
L1 ( x ) , j≠ 1
f 2 ( x )=( x− x1)( x− x2)( x0− x1 )( x0− x 2 )
f ( x0)
+( x− x0) (x− x2)( x1− x0 )( x1− x 2 )
f ( x1 )
+( x− x0)( x− x1)( x2− x0 )( x2− x 1 )
f ( x 2) L2( x ) , j≠ 2
• Second order version (n = 2):
Lo( x ) , j≠ 0
Lagrange Interpolating Polynomials -Example
Use a Lagrange interpolating polynomial of the first andsecond order to evaluate ln(2) on the basis of the data:
x 0=1 f ( x 0 )=ln (1 )=0
x 1=4x 2=6
f ( x 1 )=ln (4 )=1.386294f ( x 2)=ln (6)=1.791760
Lagrange Interpolating Polynomials –Example (cont’d)
● First order polynomial:
f 1( x )=x− x 1
x 0− x 1f ( x 0)+
x− x 0
x 1− x 0f ( x 1 )
f 1( 2)=2− 41− 4
⋅ 0+ 2− 14− 1
⋅ 1 . 386294=0 . 4620981
Lagrange Interpolating Polynomials –Example (cont’d)
● Second order polynomial:
60
6x
40
4x
xx
xx
xx
xxxL
2o
2
1o
1o −
−⋅−−=
−−⋅
−−=)(
64
6x
04
0x
xx
xx
xx
xxxL
21
2
o1
o1 −
−⋅−−=
−−⋅
−−=)(
46
4x
06
0x
xx
xx
xx
xxxL
12
1
o2
o2 −
−⋅−−=
−−⋅
−−=)(
Lagrange Interpolating Polynomials –Example (cont’d)
f 2 (2)=(2− 4 )(2− 6)(1− 4 )(1− 6)
⋅ 0
+( 2− 1)( 2− 6 )( 4− 1 )(4− 6)
⋅ 1.386294
+(2− 1)(2− 4 )(6− 1)(6− 4 )
1.791760=0 . 5658444
∑=
=n
0iiin xfxLxf )()()( )()( ij
xx
xxxL
n
0j ji
ji ≠
−−
= ∏=
Lagrange Interpolating Polynomials –Example (cont’d)
Coefficients of an Interpolating Polynomial
● Although “Lagrange” polynomials are well suitedfor determining intermediate values betweenpoints, they do not provide a polynomial inconventional form:
● Since n+1 data points are required to determinen+1 coefficients, simultaneous linear systems ofequations can be used to calculate “a”s.
f ( x )=a0+a1 x+a2 x2+⋯ +a x xn
Coefficients of an InterpolatingPolynomial (cont’d)
f ( x0 )=a0+a1 x0+a2 x02⋯ +an x0
n
f ( x1 )=a0+a1 x1+a2 x12⋯ +an x1
n
⋮f ( xn )=a0+a1 xn+a2 x n
2⋯ +an xnn
Where “x”s are the knowns and “a”s are theunknowns.
Possible divergence of an extrapolatedproduction
20
Why Spline Interpolation?
Apply lower-order polynomials to subsets of data points. Splineprovides a superior approximation of the behavior of functions thathave local, abrupt changes.
Spline Interpolation
● Polynomials are the most common choice ofinterpolants.
● There are cases where polynomials can lead toerroneous results because of round off error andovershoot.
● Alternative approach is to apply lower-orderpolynomials to subsets of data points. Suchconnecting polynomials are called splinefunctions.
22
Why Splines ?
f ( x )=1
1+25 x2
Table : Six equidistantly spaced points in [-1, 1]
Figure : 5th order polynomial vs. exact function
x 2251
1
xy
+=
-1.0 0.038461
-0.6 0.1
-0.2 0.5
0.2 0.5
0.6 0.1
1.0 0.038461
23
Why Splines ?
Figure : Higher order polynomial interpolation is a bad idea
OriginalFunction
17th OrderPolynomial
9th OrderPolynomial
5th OrderPolynomial
Spline InterpolationThe concept of spline is using a thin , flexible strip(called a spline) to draw smooth curves through aset of points….natural spline (cubic)
Linear Spline
The first order splines for a group of ordered datapoints can be defined as a set of linear functions:
mi=f ( xi+1 )− f ( x i )
x i+1− x i
f ( x )= f ( x0)+m0( x− x0 ) x0≤ x≤ x1
f ( x )= f ( x1 )+m1 ( x− x1 ) x1≤ x≤ x2
f ( x )= f ( xn− 1 )+mn− 1 ( x− x n− 1 ) xn− 1≤ x≤ xn
⋮
Linear spline - ExampleFit the following data with first order splines. Evaluatethe function at x = 5.
x f(x)
3.0 2.54.5 1.07.0 2.59.0 0.5
m=2. 5− 17− 4 . 5
=0 . 6
f (5)= f (4 .5 )+m(5− 4 .5)=1 . 0+0 . 6×0. 5=1 . 3
Linear Spline● The main disadvantage of linear spline is that
they are not smooth. The data points where 2splines meets called (a knot), the changesabruptly.
● The first derivative of the function is discontinuousat these points.
● Using higher order polynomial splines ensuresmoothness at the knots by equating derivativesat these points.
Quadric Splines
f i( x )=a i x2+bi x+ci
• Objective: to derive a second order polynomial for eachinterval between data points.• Terms: Interior knots and end points
For n+1 data points:• i = (0, 1, 2, …n),• n intervals,• 3n unknownconstants (a’s, b’s andc’s)
Quadric Splines (3n conditions)
● The function values of adjacent polynomialmust be equal at the interior knots 2(n-1).
● The first and last functions must passthrough the end points (2).
a i− 1 xi− 1
2+bi− 1 xi− 1+ci− 1= f i ( xi− 1 ) i=2, 3, 4, . .. , n
a i xi− 1
2+b i x i− 1+ci= f i( xi− 1 ) i=2, 3, 4, . .. , n
a1 x0
2+b1 x0+c1= f ( x0 )
an xn
2+bn xn+cn= f ( xn )
Quadric Splines (3n conditions)● The first derivatives at the interior knots
must be equal (n-1).
● Assume that the second derivate is zeroat the first point (1)
(The first two points will be connected by a straight line)
fi' ( x )=2ai x+bi
2ai− 1 x i− 1+bi− 1=2a i xi− 1+bi
a 1=0
Quadric Splines - Example
Fit the following data with quadraticsplines. Estimate the value at x = 5.
Solutions:There are 3 intervals (n=3), 9 unknowns.
x 3.0 4.5 7.0 9.0
f(x) 2.5 1.0 2.5 0.5
Quadric Splines - Example1. Equal interior points:
For first interior point (4.5, 1.0)
The 1st equation:
The 2nd equation:
Quadric Splines - Example
For second interior point (7.0, 2.5)
The 3rd equation:
The 4th equation:
49 a2+7b2+c2=2. 5
49 a3+7b3+c3=2 .5
x22 a2+ x2 b2+c2= f ( x2 )
(7)2 a2+7b2+c2= f (7)
x22 a3+x2 b3+c3= f ( x2 )
(7)2 a3+7b3+c3= f (7 )
Quadric Splines - Example
First and last functions pass the endpoints
For the start point (3.0, 2.5)
For the end point (9, 0.5)
9a1+3b1+c1=2. 5
81a3+9b3+c3=0 .5
x02 a1+x0 b1+c1= f ( x0 )
x32 a1+x3 b3+c3= f ( x3 )
Quadric Splines - ExampleEqual derivatives at the interior knots.
For first interior point (4.5, 1.0)
For second interior point (7.0, 2.5)
Second derivative at the first point is 0
Quadric Splines - Example
[ ] [ ] [ ] [ ] [ ] [ ] [ ]
righ
righ
c
b
a
c
b
a
c
b
[]
righ
0
0
0.5
2.5
2.5
2.5
1
1
0114011400
00001901
198100000
00000013
174900000
000174900
00014.520.2500
00000014.5
3
3
3
2
2
2
1
1
−−−−
Quadric Splines - ExampleSolving these 8 equations with 8 unknowns
a1=0, b1=− 1, c1=5 . 5
a2=0 . 64 , b2=− 6. 76 , c2=18. 46a3=− 1. 6, b3=24. 6, c3=− 91. 3
f 1( x )=− x+5. 5, 3 .0≤ x≤ 4 . 5
f 2 ( x )=0. 46 x2− 6 .76 x+18 . 46 , 4 . 5≤ x≤ 7 . 0
f 3( x )=− 1. 6x2+24 .6x− 91. 3, 7 . 0≤ x≤ 9 .0
Cubic Splines
f i( x )=a i x3+bi x2+c i x+d i
Objective: to derive a third order polynomial foreach interval between data points.Terms: Interior knots and end points
For n+1 data points:• i = (0, 1, 2, …n),• n intervals,• 4n unknown constants (a’s, b’s ,c’s and d’s)
Cubic Splines (4n conditions)● The function values must be equal at the interior
knots (2n-2).● The first and last functions must pass through the
end points (2).● The first derivatives at the interior knots must be
equal (n-1).● The second derivatives at the interior knots must
be equal (n-1).● The second derivatives at the end knots are zero (2),
(the 2nd derivative function becomes a straight line atthe end points)
Alternative technique to get CubicSplines● The second derivative within each interval [xi-1, xi ] is a straight line.
(the 2nd derivatives can be represented by first order Lagrangeinterpolating polynomials.
fi''( x )= f
i''( xi− 1)
x− x i
x i− 1− x i
+ fi''( xi )
x− x i− 1
xi− xi− 1
A straight lineconnecting the firstknot f’’(xi-1) and thesecond knot f’’(xi)
The second derivative at any point x within the interval
Cubic Splines● The last equation can be integrated twice
2 unknown constants of integration can be evaluatedby applying the boundary conditions:1. f(x) = f (xi-1) at xi-1
2. f(x) = f (xi) at xi
Unknowns:
i = 0, 1,…, n
Cubic Splines
( xi− x i− 1) f ''( x i− 1)+2( xi+1− x i− 1 ) f ''( xi )
+( x i+1− xi ) f ''( xi+1 )=6x i+1− xi
[ f ( x i+1 )− f ( xi )]
+6xi− xi− 1
[ f ( x i− 1)− f ( x i)]
• For each interior point xi (n-1):
This equation result with n-1 unknown secondderivatives where, for boundary points:f˝(xo) = f˝(xn) = 0
fi− 1
' ( x i )= f i' ( x i)
Cubic Splines - Example
Fit the following data with cubic splinesUse the results to estimate the value at x=5.
Solution:
Natural Spline:
x 3.0 4.5 7.0 9.0
f(x) 2.5 1.0 2.5 0.5
f ''( x0)= f ''(3 )=0, f ''( x3 )= f ''(9 )=0
Cubic Splines - Example For 1st interior point (x1 = 4.5)
---Apply the following equation:
( xi− x i− 1) f ''( x i− 1)+2( xi+1− x i− 1 ) f ''( xi )+( x i+1− x i) f ''( xi+1 )
¿6xi+1− x i
[ f ( xi+1 )− f ( x i )] +6x i− xi− 1
[ f ( xi− 1 )− f ( xi )]
x 3.0 4.5 7.0 9.0
f(x) 2.5 1.0 2.5 0.5x i− x i− 1=x1− x0=4 . 5− 3 . 0=1. 5
x i+1− xi= x2− x1=7− 4.5=2 . 5
x i+1− xi− 1= x2− x0=7− 3. 0=4
Cubic Splines - Example
1. 5f ''(3 )+2×4f ''(4 .5)+2 . 5f ''(7 )=6
2 . 5(2 . 5− 1 )+
61 .5(2 . 5− 1 )
f ''(3 )=0
8f ''( 4. 5 )+2 .5f ''(7)=9. 6 .. . .. .. . .. .. . . (eq .1 )
x 3.0 4.5 7.0 9.0
f(x) 2.5 1.0 2.5 0.5
Since
For 2nd interior point (x2 = 7 )
x i− x i− 1=x2− x1=7− 4 . 5=2. 5
x i+1− xi− 1= x3− x1=9− 4 . 5=4 . 5
x i+1− xi= x3− x2=9− 7=2
Cubic Splines - Example
Apply the following equation:
( xi− x i− 1) f ''( x i− 1)+2( xi+1− x i− 1 ) f ''( xi )+( x i+1− x i) f ''( xi+1 )
¿6xi+1− x i
[ f ( xi+1 )− f ( x i )] +6x i− xi− 1
[ f ( xi− 1 )− f ( xi )]
2 . 5f ''( 4. 5)+2×4 .5f ''(7)+2f ''(9 )=62(0. 5− 2 . 5)+
62.5(1− 2. 5)
Since f ''(9 )=0
2 . 5f ''(4 . 5)+9f ''(7 )=− 9 .6 . .. .. . .. .. . .. ( equ 2 )
Cubic Splines - ExampleSolve the two equations:
The first interval (i=1), apply for the equation:
8f i''( 4. 5 )+2 .5f i
''(7)=9.6
2. 5f i''( 4. 5 )+9f i
''(7)=− 9 . 6
¿ }¿¿ yeild f ''(4 . 5)=1. 67909 , f ''(7)=− 1 .53308¿
f i( x )=f
i''( xi− 1 )
6( x i− x i− 1)(xi− x )3+
fi''( xi )
6( xi− xi− 1 )( x− xi− 1)
3
+[ f i ( xi− 1)xi− xi− 1
−f
i''( xi− 1 )(xi− x i− 1)
6 ]( x i− x)+[ f i( x i )xi− x i− 1
−f
i''( xi )(x i− x i− 1)
6 ]( x− x i− 1)
f 1( x )=0 .186566 ( x− 3 )3+1 .6667 (4 . 5− x )+0 . 24689( x− 3 )
f 1( x )=0 ( xi− 3 )3+1. 679096(1. 5)
( x− 3 )3+[ 2 . 51 . 5
− 0(1.5 )6 ](4 . 5− x )+[ 1
1. 5− 1. 67909(1. 5)
6 ]( x− 3)
Cubic Splines - Example
f 2 ( x )=1 . 679096 (2 .5 )
(7− x )3+− 1 .533086(2 .5 )
( x− 4 .5 )3+[12 .5− − 1. 67909(2 .5)
6 ](7− x)
+[2.52.5
− − 1 . 53308(2 . 5)6 ]( x− 4 . 5)
f 2 ( x )=0. 111939(7− x )3− 0 . 102205 ( x− 4 .5 )3− 0 . 29962(7− x )+1. 638783 ( x− 4 . 5)
f 3( x )=− 0 .127757 (9− x )3+1.761027 (9− x )+0. 25 ( x− 7 )
f 2 ( x )= f 2(5)=1. 102886
The 2nd interval (i =2), apply for the equation:
The 3rd interval (i =3),
For x = 5:
Credits:● Chapra, Canale● The Islamic University of Gaza, Civil Engineering Department