05.Interpolation

Download Report

Transcript 05.Interpolation

Interpolation - Introduction
Estimation of intermediate values between
precise data points. The most common method is
polynomial interpolation:
f ( x )= a 0 +a1 x+a 2 x 2 +⋯+a n x n


Polynomial interpolation is used when the point
determined are very precise. The curve
representing the behavior has to pass through
every point.
There is one and only one nth-order polynomial
that fits n+1 points
Introduction
n=2
First order (linear)
n=3
2nd order (quadratic)
n=4
3rd order (cubic)
Interpolation
Polynomials are the most common
choice of interpolation because they
are easy to:
Evaluate
Differentiate, and
Integrate.
3
Introduction
There are a variety of mathematical formats in which this
polynomial can be expressed:
The Newton polynomial (sec. 18.1)
The Lagrange polynomial (sec. 18.2)
Newton’s Divided-Difference
Interpolating Polynomials
Linear Interpolation/
Is the simplest form of interpolation, connecting two data points
with a straight line.
f1 ( x)  f ( x0 ) f ( x1 )  f ( x0 )

x  x0
x  x0
Slope and a
finite divided
difference
approximation to
1st derivative
f ( x1 )  f ( x0 )
f1 ( x)  f ( x0 ) 
( x  x0 ) Linear-interpolation
x  x0
formula
f1(x) designates that this is a first-order interpolating polynomial.
5
Figure
18.2
6
Quadratic Interpolation/
If three data points are available, the estimate is improved
by introducing some curvature into the line connecting
the points.
f 2 ( x)  b0  b1 ( x  x0 )  b2 ( x  x0 )(x  x1 )
A simple procedure can be used to determine the values
of the coefficients.
x  x0
b0  f ( x0 )
x  x1
f ( x1 )  f ( x0 )
b1 
x  x0
x  x2
f ( x2 )  f ( x1 ) f ( x1 )  f ( x0 )

x2  x1
x1  x0
b2 
x2  x0
7
General Form of Newton’s Interpolating Polynomials/
f n ( x)  f ( x0 )  ( x  x0 ) f [ x1 , x0 ]  ( x  x0 )(x  x1 ) f [ x2 , x1 , x0 ]
   ( x  x0 )(x  x1 )  ( x  xn 1 ) f [ xn , xn 1 ,  , x0 ]
b0  f ( x0 )
b1  f [ x1 , x0 ]
b2  f [ x2 , x1 , x0 ]

bn  f [ xn , xn 1 ,  , x1 , x0 ]
f [ xi , x j ] 
f ( xi )  f ( x j )
f [ xi , x j , xk ] 
xi  x j
f [ xi , x j ]  f [ x j , xk ]
Bracketed function
evaluations are finite
divided differences
xi  xk

f [ xn , xn 1 ,  , x1 , x0 ] 
f [ xn , xn 1 ,  , x1 ]  f [ xn 1 , xn  2 ,  , x0 ]
xn  x0
8
Lagrange Interpolating Polynomials
The general form for n+1 data points is:
n
f n ( x)   Li ( x) f ( xi )
i 0
n
Li ( x)  
j 0
j i
x  xj
xi  x j
designates the “product of”
Lagrange Interpolating Polynomials
• Linear version (n = 1):
Used for 2 points of data: (xo,f(xo)) and (x1,f(x1)),
x− x 1
x− x 0
f 1 ( x )=
f ( x 0 )+
f ( x1 )
x 0− x 1
x 1− x 0
L o( x)
L1 ( x)
Lagrange Interpolating
Polynomials
• Second order version (n = 2):
x− x 1 )(x− x 2 )
(
f 2 ( x )=
f ( x 0)
(x 0− x1 )(x 0− x 2 )
x− x 0 )(x − x 2 )
(
+
f ( x1 )
(x1 − x 0 )(x1 − x 2 )
x− x 0 )(x− x1 )
(
+
f ( x 2)
(x 2 − x 0 )(x 2 − x 1 )
L o( x) , j≠ 0
L1 ( x) , j≠ 1
L 2( x ) , j≠ 2
Lagrange Interpolating Polynomials Example
Use a Lagrange interpolating polynomial of the first and
second order to evaluate ln(2) on the basis of the data:
x 0= 1
x 1= 4
x 2= 6
f ( x 0 )= ln(1)= 0
f ( x 1 )= ln (4)= 1.386294
f ( x 2 )= ln(6)= 1.791760
Lagrange Interpolating Polynomials –
Example (cont’d)
●
First order polynomial:
x− x 1
x− x 0
f 1 ( x)=
f ( x 0 )+
f ( x1)
x 0− x 1
x 1− x 0
2− 4
2− 1
f 1 ( 2)=
⋅ 0+
⋅ 1 . 386294= 0 . 4620981
1− 4
4− 1
Lagrange Interpolating Polynomials –
Example (cont’d)
●
Second order polynomial:
x

x

x

4
x

6
1x
2 x
L
(
x
)
 

o
x

x
x

x

4
0

6
o
1
o
20
x

x

x

0
x

6
ox
2 x
L
(
x
)
 

1
x

x

x

0
4

6
1
ox
1
24
x

x

x

0
x

4
ox
1 x
L
(
x
)
 

2
x

x

x

0
6

4
2
ox
2
16
Lagrange Interpolating Polynomials –
Example (cont’d)
n
fn(
x
)
L
x
)f(
x

i(
i)
i
0
n
x

x
j
L
x
)
(
j
i
)

i(
x
j

0x
i
j
(2− 4 )(2− 6)
f 2 (2)=
⋅0
(1− 4 )(1− 6)
( 2− 1)( 2− 6)
+
⋅ 1.386294
( 4− 1 )(4− 6)
(2− 1)(2− 4)
+
1.791760= 0. 5658444
(6− 1)(6− 4)
Lagrange Interpolating Polynomials –
Example (cont’d)
Coefficients of an Interpolating Polynomial
●
Although “Lagrange” polynomials are well suited
for determining intermediate values between
points, they do not provide a polynomial in
conventional form:
2
n
f ( x )= a 0 +a1 x+a 2 x +⋯+a x x
●
Since n+1 data points are required to determine
n+1 coefficients, simultaneous linear systems of
equations can be used to calculate “a”s.
Coefficients of an Interpolating
Polynomial (cont’d)
f ( x 0 )= a 0 +a 1 x 0 +a 2 x 20 ⋯+a n x n0
f ( x1 )=
2
n
a 0 +a1 x1 +a 2 x1 ⋯+a n x 1
f ( x n )=
2
n
a 0 +a 1 x n +a 2 x n ⋯+a n x n
⋮
Where “x”s are the knowns and “a”s are the
unknowns.
Possible divergence of an extrapolated
production
Why Spline Interpolation?
Apply lower-order polynomials to subsets of data points. Spline
provides a superior approximation of the behavior of functions that
have local, abrupt changes.
20
Why Splines ?
1
f ( x )=
1+25 x 2
Table : Six equidistantly spaced points in [-1, 1]
x
y
1
1  25 x 2
-1.0
0.038461
-0.6
0.1
-0.2
0.5
0.2
0.5
0.6
0.1
1.0
0.038461
Figure : 5th order polynomial vs. exact function
21
Why Splines ?
17thO
rder
Polynom
ial
O
riginal
Function
5thO
rder
Polynom
ial
9thO
rder
Polynom
ial
Figure : Higher order polynomial interpolation is a bad idea
22
Spline Interpolation
●
●
●
Polynomials are the most common choice of
interpolants.
There are cases where polynomials can lead to
erroneous results because of round off error and
overshoot.
Alternative approach is to apply lower-order
polynomials to subsets of data points. Such
connecting polynomials are called spline
functions.
Spline provides a superior approximation of the behavior
of functions that have local, abrupt changes (d).
Spline Interpolation
The concept of spline is using a thin , flexible strip
(called a spline) to draw smooth curves through a
set of points….natural spline (cubic)
Linear Spline
The first order splines for a group of ordered data
points can be defined as a set of linear functions:
f ( x)= f ( x 0)+m0( x− x 0 )
x 0≤ x ≤ x1
f ( x)= f ( x1 )+m1 ( x− x 1 )
x 1 ≤ x≤ x 2
⋮
f ( x)= f ( x n− 1 )+mn− 1 ( x− x n− 1 )
x n− 1≤ x≤ x n
f ( xi+1 )− f ( x i )
mi =
x i+1 − x i
Linear spline - Example
Fit the following data with first order splines. Evaluate
the function at x = 5.
x
f(x)
3.0
4.5
7.0
9.0
2.5
1.0
2.5
0.5
2. 5− 1
m=
= 0.6
7− 4 . 5
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 2
splines meets called (a knot), the changes
abruptly.
The first derivative of the function is discontinuous
at these points.
Using higher order polynomial splines ensure
smoothness at the knots by equating derivatives
at these points.
Quadric Splines
• Objective: to derive a second order polynomial for each
interval between data points. f i ( x )= a i x 2 +bi x+ci
• Terms: Interior knots and end points
For n+1 data points:
• i = (0, 1, 2, …n),
• n intervals,
• 3n unknown
constants (a’s, b’s and
c’s)
Quadric Splines
●
The function values of adjacent polynomial
must be equal at the interior knots 2(n-1).
a i− 1 x
ai x
●
i− 1
i− 1
2 +bi− 1 x i− 1 +ci− 1=
2 +b i x i− 1 +ci =
f i ( x i− 1 ) i= 2, 3, 4, . .. , n
f i ( xi− 1 )
i= 2, 3, 4, . .. , n
The first and last functions must pass
through the end points (2).
a 1 x 2 + b1 x 0 + c1 = f ( x 0 )
0
a n x 2 +b n x n + c n = f ( x n )
n
Quadric Splines
●
The first derivatives at the interior knots
must be equal (n-1).
f ' ( x)= 2ai x+bi
i
2a i− 1 x i− 1 +bi− 1 = 2a i xi− 1 +bi
●
Assume that the second derivate is zero
at the first point (1)
a 1= 0
(The first two points will be connected by a straight line)
Quadric Splines - Example
Fit the following data with quadratic
splines. Estimate the value at x = 5.
x
f(x)
3.0
4.5
7.0
9.0
2.5
1.0
2.5
0.5
Solutions:
There are 3 intervals (n=3), 9 unknowns.
Quadric Splines - Example
1. 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:
x 22 a 2 + x 2 b2 +c 2 = f ( x 2 )
2
( 7) a 2 +7b2 +c 2 = f ( 7)
49 a 2 +7b 2 + c2 = 2. 5
The 4th equation:
2
x 2 a 3 +x 2 b3 +c 3=
f ( x2 )
(7) 2 a 3 +7b 3 +c3 = f (7 )
49 a3 +7b3 +c 3 = 2 .5
Quadric Splines - Example

First and last functions pass the end
points
For the start point (3.0, 2.5)
9a 1 +3b1 + c 1= 2. 5
x 20 a 1 +x 0 b1 +c1 = f ( x 0 )
For
2 the end point (9, 0.5)
x 3 a1 +x 3 b 3 +c 3 = f ( x 3 )
81 a 3 +9b 3 +c 3 = 0 . 5
Quadric Splines - Example
Equal 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
0
0
4 . 51 0 0
0
0 0 0
0
2 0 . 2 54 . 51 0 0 0
0
0
3 1
0
1
0
0
0
0 4 9 7
0
0
0
0 0
0
0
 9
1 4
0
 1
1
1 0 0
0 4 9
0 0
0 8 1
0
0
0  1 4
0
7 1
0
9
1
0
0
 1 0
rig h
[
]
b
1
c1
a2
b2
c2
a3
b3
c3
rig h
1
1
2 .5
2 .5
2 .5
0 .5
0
0
rig h














Quadric Splines - Example
Solving these 8 equations with 8 unknowns
a 1 = 0, b1 = − 1, c 1= 5 . 5
a 2 = 0 . 64 , b 2 = − 6. 76 , c 2 = 18. 46
a 3 = − 1. 6, b3 = 24. 6, c 3 = − 91. 3
f 1 ( x )= − x +5. 5,
3 .0≤ x ≤ 4 . 5
f 2 ( x )= 0. 46 x 2 − 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
Objective: to derive a third order polynomial for
each interval between data points.
Terms: Interior knots and end points
3
2
f i ( x )= a i x +bi x +c i x +d i
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
●
●
●
●
●
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 at
the end points)
Alternative technique to get Cubic
Splines
●
The second derivative within each interval [xi-1, xi ] is a straight line.
(the 2nd derivatives can be represented by first order Lagrange
interpolating polynomials.
x− x i
x− x i− 1
f ''( x )= f '' ( xi− 1 )
+ f ''( xi )
i
i
x i− 1− x i i
xi − x i− 1
A straight line
connecting the first
knot f’’(xi-1) and the
second 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 evaluated
by 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
• For each interior point xi (n-1):
f 'i− 1 ( x i )= f i ( x i )
'
( x i− x i− 1 ) f '' ( x i− 1 )+2( x i+1 − x i− 1 ) f ''( x i )
6
''
+( x i+1 − x i ) f ( x i+1 )=
f ( x i+1 )− f ( xi ) ]
[
x i+1 − x i
6
+
f ( x i− 1 )− f ( x i ) ]
[
x i − x i− 1
This equation result with n-1 unknown second
derivatives where, for boundary points:
f˝(xo) = f˝(xn) = 0
Cubic Splines - Example
Fit the following data with cubic splines
Use the results to estimate the value at x=5.
x
3.0
4.5
7.0
9.0
f(x)
2.5
1.0
2.5
0.5
Solution:
 Natural Spline:
f '' ( x 0 )= f '' (3 )= 0, f '' ( x 3 )= f '' (9 )= 0
Cubic Splines - Example
 For 1st interior point (x1 = 4.5)
x
3.0
4.5
7.0
9.0
f(x)
2.5
1.0
2.5
- x i − x i− 1= x 1− x 0= 4. 5− 3. 0= 1. 5
0.5
- x i+1− xi− 1= x 2− x 0= 7− 3. 0= 4
- x i+1− xi = x 2− x 1= 7− 4. 5= 2. 5
Apply the following equation:
( x i− x i− 1 ) f '' ( x i− 1 )+2( x i+1 − x i− 1 ) f ''( x i )+( x i+1− x i ) f ''( xi+1 )
6
6
¿
f ( xi+1 )− f ( x i ) ] +
f ( xi− 1 )− f ( xi ) ]
[
[
xi+1 − x i
x i− xi− 1
Cubic Splines - Example
6
6
1. 5f (3 )+2× 4f (4 . 5)+2 . 5f (7 )=
(2 . 5− 1 )+
(2 . 5− 1 )
2.5
1 .5
''
f
(3)= 0
Since
''
''
''
8f ''( 4.5)+2.5f '' (7)= 9.6 .............. (eq.1)
 For 2nd interior point (x2 = 7 )
x
3.0
4.5
7.0
9.0
f(x)
2.5
1.0
2.5
0.5
x i − x i− 1 = x 2− x 1 = 7− 4. 5= 2. 5
x i+1− xi− 1= x 3− x1= 9− 4. 5= 4. 5
x i+1− xi = x3− x 2= 9− 7= 2
Cubic Splines - Example
Apply the following equation:
( x i− x i− 1 ) f '' ( x i− 1 )+2( x i+1 − x i− 1 ) f ''( x i )+( x i+1− x i ) f ''( xi+1 )
6
6
¿
f ( xi+1 )− f ( x i ) ] +
f ( xi− 1 )− f ( xi ) ]
[
[
xi+1 − x i
x i− xi− 1
6
6
2 . 5f ( 4. 5)+2× 4 .5f (7)+2f (9 )= (0. 5− 2 . 5)+
(1− 2. 5)
2
2. 5
''
Since
''
''
''
''
f (9)= 0
''
2.5f (4.5)+9f (7)=− 9.6 ............. ( equ 2)
Cubic Splines - Example
Solve the two equations:
8 f ''i ( 4 . 5 )+ 2 . 5 f ''i ( 7 )= 9 . 6
2 . 5 f ''i ( 4 . 5 )+9 f i'' ( 7 )= − 9 . 6
¿}¿
¿ yeild
f
''
( 4 . 5 )= 1 . 67909 ,
f
''
( 7 )= − 1 . 53308 ¿
The first interval (i=1), apply for the equation:
[
i
i
3
f '' ( xi )
3
xi − x ) + i
(
(x− x i− 1)
6 (x i − x i− 1 )
6 (xi − xi− 1 )
f i ( xi − 1 ) f i'' ( x i− 1 ) (x i − x i− 1 )
f i( xi )
−
x
−
x
+
( i ) x−x
x−x
6
f i ( x )=
+
f '' ( x i− 1 )
] [
i− 1
[
i
i− 1
]
−
f ''( x i ) (x i − x i− 1 )
i
6
[
]
(x− x i− 1 )
]
1. 67909
2 . 5 0(1. 5 )
1 1. 67909(1. 5)
3
f 1 ( x)= 0 ( xi − 3 ) +
( x− 3 ) +
−
(4 . 5− x )+
−
( x− 3)
6(1. 5)
1.5
6
1. 5
6
3
f 1 ( x )= 0 .186566 ( x− 3 )3 +1 .6667 (4 . 5− x )+0 . 24689( x− 3 )
Cubic Splines - Example
The 2nd interval (i =2), apply for the equation:
1 . 67909
− 1. 67909(2 . 5)
3 − 1 .53308
3 1
f 2 ( x )=
(7− x ) +
( x− 4 .5 ) +
−
(7− x )
6 (2 .5 )
6(2 .5 )
2 .5 6
2. 5 − 1 . 53308(2 . 5)
+
−
( x− 4 . 5)
2. 5 6
[
[
]
]
f 2 ( x )= 0. 111939(7− x )3 − 0 . 102205 ( x− 4 .5 )3 − 0 . 29962(7− x )+1. 638783 ( x − 4 . 5)
The 3rd interval (i =3),
f 3 ( x)= − 0 .127757 (9− x) 3 +1. 761027 (9− x )+0. 25 ( x− 7 )
For x = 5:
f 2 ( x)= f 2(5)= 1. 102886
Credits:
●
●
Chapra, Canale
The Islamic University of Gaza, Civil Engineering Department