Post on 01-Jan-2017
transcript
1
Interpolation
“Numerical Methods with MATLAB”, Recktenwald, Chapter 10and
“Numerical Methods for Engineers”, Chapra and Canale, 5th Ed., Part Five, Chapter 18and
“Applied Numerical Methods with MATLAB”, Chapra, 2nd Ed., Part Four, Chapters 15 and 16
PGE 310: Formulation and Solution in Geosystems Engineering
Dr. Balhoff
1
How Fast are you going?
What time is it?
2
2
Basic Ideas of Interpolation
Mathematical equivalent of “reading between the lines” Data - discrete samples of some function, f(x)
Uses an interpolating function between points
Data might… Exist as an experiment
Analytic function that is difficult to evaluate
3
Interpolation versus Curve Fitting (Regression)
Interpolation Data assumed exact
Interpolating function between points
Curve passes EXACTLY through the data points
Curve Fitting Uncertainty in data
Uses a regression curve to fit data
Curve passes “near” the points
4
3
Types of Interpolation
Single Polynomial Divided Difference
Lagrange Identical
Multiple polynomials Hermite
Lagrange
5
Newton’s Divided-Difference is a Useful Form
For “n” points, I can always fit an “n-1” degree polynomial Line b/w 2 points
Parabola b/w 3 points
15th order polynomial b/w 16 points
Find coefficients of polynomial
2 10 1 2 1( ) n
nP x a a x a x a x
1 2 1 1 2 1( ) ( ) ( )n nP x b b x x b x x x x x x
Standard Form
Newton’s Divided Difference
6
4
Linear Interpolation (Simplest Divided-Difference)
2 11 1
2 1
( ) ( )( ) ( )
f x f xf x f x x x
x x
1 1 2 1( )P x b b x x
Imagine Similar Triangles:
Newton-Form:
x1 x2x
f(x1)
f(x2)
f(x)12
12
1
1 )()()()(
xx
xfxf
xx
xfxf
7
General Form- Newton’s Interpolating Polynomials
1 2 1 1 2 1( ) ( ) ( )n nP x b b x x b x x x x x x
1 1
2 1 2
3 1 2 3
1 2 1
( )
[ , ]
, ,
, , , ,n n n
b f x
b f x x
b f x x x
b f x x x x
[ , ] [ , ], , i j j ki j k
i k
f x x f x xf x x x
x x
Where the b’s are:
2 1 2 11 2
1
[ , , ] [ , , , ], , , n n
nn
f x x f x x xf x x x
x x
( ) ( ), i ji j
i j
f x f xf x x
x x
The divided differences are:
8
5
Linear Interpolation for f(x)=ln(x)
9
Quadratic Interpolation example
10
6
Higher Order Estimate
11
Lagrange Interpolating Polynomials
Lagrange is simply a reformulation of the Newton polynomial !!!! Avoids computation of Divided Differences
1
( ) ( ) ( )n
n j jj
P x L x f x
1
( )n
kj
k j kk j
x xL x
x x
1 1 2 2( ) ( ) ( ) ( )n nP x L f x L f x L f x
n
n
xx
xx
xx
xx
xx
xxL
131
3
21
21
Lagrange Form:
2 10 1 2( ) n
nP x a a x a x a x
1 2 1 1 2 1( ) ( ) ( )n nP x b b x x b x x x x x x
Standard Form:
Newton’s Form:
12
7
Problems with Single Polynomial Interpolation
“N-1” Order polynomial through “N” points
Forces oscillations which probably don’t exist naturally
Adding More points can make it worse
How do we fix the problem? Connect a series of interpolating functions
13
Review…
Unlike Curve Fitting, Interpolation goes exactly through the data points
Interpolating Polynomials: fit ‘n-1’ order polynomial to ‘n’ data points
Newton Divided Difference
Lagrange Polynomials
Divide Difference and Lagrange are equivalent!
1 2 1 1 2 1( ) ( ) ( )n nP x b b x x b x x x x x x
1 1 2 2( ) ( ) ( ) ( )n nP x L f x L f x L f x 1
( )n
kj
k j kk j
x xL x
x x
14
8
Piecewise Polynomials
Not always a good idea to fit a single polynomial to “n” data points Especially when “n” gets really big (like 10 or so) Lots of oscillations can result in error
Connect together a series of piecewise polynomials Splines
A few different types of splines Linear – functions match at “knot” points Quadratic – derivatives ALSO match at “knot” points Cubic – 1st and 2nd derivatives match at knot points
15
Piecewise Polynomial Interpolation
Practical solution to high-degree polynomial interpolation
Use set of lower degree interpolants Each defined on sub-interval of domain Used instead of single function
approximation
Relationship b/w adjacent piecewise functions is of fundamental importance Shape is affected by constraints on
continuity
16
9
Piecewise Linear Interpolation
Simplest scheme uses linear interpolants
Continuity In function at breakpoints
But NOT in the derivatives
Calculate linear interpolants using Lagrange
2
12
11
21
222111 )( y
xx
xxy
xx
xxyLyLxf
Linear Lagrange polynomial
For each (n-1) sub-section
1,...,2,1)( 1
11
1
niyxx
xxy
xx
xxxf i
ii
ii
ii
ii
17
Cubic Spline
18
10
Cubic Spline Interpolation
Basic Idea: Force continuity in 1st and 2nd derivatives at knots
(n-1) splines & 4 coefficients each = 4*(n-1) unknowns1. 2(n-1) known function values
2. n-2 derivatives must be equal at INTERIOR knots
3. n-2 second derivatives must be equal at INTERIOR knots
4n-6 constraints, but 4n-4 unknowns – need 2 more constraints!
iiiii dxcxbxaxf 23)(Standard Form:
Lagrange Form: We will derive….
Find the coefficients for each n-1 polynomials
19
Options for Additional Constraints on End Points?
1. Fixed-slope end conditions – constrain the first derivative on the 2 end points
2. “Not-a-knot” end conditions – requires continuity in third derivative at first internal knot. Most accurate condition
3. “Natural” spline end condition – force second derivative equal to zero (We’ll use this one)
0)("0)(" 1 nxfandxf
(These are the last two constraints I need!)
20
11
Cubic Spline Derivation
Forcing continuity in 2nd derivative gives:
Integrating equation twice gives cubic spline formula
" "1
"
3 3
11 1
11
1
1 1
1
"1
( ) ( )( )
6( ) 6( )
( ) ( )
( )
( )
6
( ) ( )
6
i i ii i i i
i i ii
i i
i i ii
i i i i
i
i i
i
i
i
f x f x
f x
f x x x x xx x x x
f x x xx x
x x
f x xf x xx x
x x
Can plug in xi’s and f(xi)’s, but still don’t know the 2nd derivatives
" "11
1 1
"( ) ( ) ( )i ii i i i i
i i i i
x x x xf x f x f x
x x x x
21
Calculate Second Derivatives for Cubic Spline
"1 21 2 2 1
2 1 12 1 1
( ) "( ) "( )( ) 2( ) ( )
6 6[ ( ) ( )] ( ) ( )
i i i i i i
i i i ii i
i
i i
i ix x xf x f xx x x
f x f x f x f x
f
x x
x
x x
But First derivates must be equal at the internal knots
Differentiate the cubic spline equation and equate:
Write the above equation for each internal knot and substitute second derivative = 0 for end points (natural end condition) results in as many equations as unknowns.
Solving for second derivatives, I can then plug back into cubic spline equation
' '1 1 1( ) ( )i i i if x f x
22
12
Conclusion
Curve Fitting: Best Fit curve to data
Interpolation: Function passes THROUGH all the data Newton/Lagrange: n-1 order polynomial for n points
Hermite and Spline: Piecewise polynomials
Cubic Spline Does not require knowledge of derivatives a priori
Forces continuity of first and second derivative
23