nm2012s lecture17 polynomial interpolation
TRANSCRIPT
-
8/12/2019 NM2012S Lecture17 Polynomial Interpolation
1/24
Polynomial Interpolation
BerlinChenDepartmentofComputerScience&InformationEngineering
NationalTaiwan
Normal
University
Reference:
1.Applied Numerical Methods with MATLAB for Engineers, Chapter 17 & Teaching material
-
8/12/2019 NM2012S Lecture17 Polynomial Interpolation
2/24
Chapter Objectives (1/2)
Recognizing that evaluating polynomial coefficients with
simultaneous equations is an ill-conditioned problem
Knowing how to evaluate polynomial coefficients andinterpolate with MATLABs polyfit and polyval functions
Knowing how to perform an interpolation with Newtons
polynomial
Knowing how to perform an interpolation with a
Lagrange polynomial
NM Berlin Chen 2
-
8/12/2019 NM2012S Lecture17 Polynomial Interpolation
3/24
Chapter Objectives (2/2)
Knowing how to solve an inverse interpolation problem
by recasting it as a roots problem
Appreciating the dangers of extrapolation
Recognizing that higher-order polynomials can manifest
large oscillations
NM Berlin Chen 3
-
8/12/2019 NM2012S Lecture17 Polynomial Interpolation
4/24
Polynomial Interpolation
You will frequently have occasions to estimate
intermediate values between precise data points
The function you use to interpolate must pass throughthe actual data points - this makes interpolation more
restrictive than fitting
The most common method for this purpose is polynomialinterpolation, where an (n-1)th order polynomial is solved
that passes through n data points:
NM Berlin Chen 4
f(x) a1 a2x a3x2 anxn1
MATLAB version :
f(x) p1xn1 p2x
n2 pn1x pn
-
8/12/2019 NM2012S Lecture17 Polynomial Interpolation
5/24
Determining Coefficients
Since polynomial interpolation provides as many basis
functions as there are data points (n), the polynomial
coefficients can be found exactly using linear algebra For n data points, there is one and only one polynomial of order
(n-1) that passes through all the points
MATLABs built in polyfit and polyval commands canalso be used - all that is required is making sure the
order of the fit for n data points is n-1
NM Berlin Chen 5
-
8/12/2019 NM2012S Lecture17 Polynomial Interpolation
6/24
Polynomial Interpolation Problems
One problem that can occur with solving for the
coefficients of a polynomial is that the system to be
inverted is in the form:
Matrices such as that on the left are known as
Vandermonde matrices, and they are very ill-conditioned- meaning their solutions are very sensitive to round-offerrors
The issue can be minimized by scaling and shifting thedata
NM Berlin Chen 6
x1n1 x1
n2 x1 1
x2n1 x2
n2 x2 1
xn1n1 xn1
n2 xn1 1
xnn1 xn
n2 xn 1
p1p2
pn1pn
f x1 f x2
f xn1 f xn
-
8/12/2019 NM2012S Lecture17 Polynomial Interpolation
7/24
Newton Interpolating Polynomials
Another way to express a polynomial interpolation is to
use Newtons interpolating polynomial
The differences between a simple polynomial and
Newtons interpolating polynomial for first and second
order interpolations are:
NM Berlin Chen 7
Order Simple Newton1st f1(x) a1 a2x f1(x) b1 b2(x x1)2nd f2 (x) a1 a2x a3x
2 f2 (x) b1 b2(x x1) b3(x x1)(x x2 )
12
122
11
)()(
)(
xx
xfxfb
xfb
13
12
12
23
23
3
)()()()(
xx
xx
xfxf
xx
xfxf
b
-
8/12/2019 NM2012S Lecture17 Polynomial Interpolation
8/24
Newton Interpolating Polynomials (1/3)
The first-order Newton
interpolating polynomial
may be obtained fromlinear interpolation and
similar triangles, as shown
The resulting formula
based on known pointsx1andx2 and the values of
the dependent function at
those points is:
NM Berlin Chen 8
112
1211
1211
xx
xx
xfxfxfxf
xxbbxf
12
12
1
11
xx
xfxf
xx
xfxf
designateafirstorderpolynomial
-
8/12/2019 NM2012S Lecture17 Polynomial Interpolation
9/24
Linear Interpolation: An Example
NM Berlin Chen 9
Thesmallertheintervalbetweenthe
data
points,
the
better
the
approximation.
Example 17.2
-
8/12/2019 NM2012S Lecture17 Polynomial Interpolation
10/24
Newton Interpolating Polynomials (2/3)
The second-order Newton
interpolating polynomial
introduces some curvatureto the line connecting the
points, but still goes through
the first two points
The resulting formula based
on known pointsx1,x2, and
x3 and the values of the
dependent function at thosepoints is:
NM Berlin Chen 10
2113
12
12
23
23
1
12
1212
2131212
xxxxxx
xx
xfxf
xx
xfxf
xxxx
xfxfxfxf
xxxxbxxbbxf
-
8/12/2019 NM2012S Lecture17 Polynomial Interpolation
11/24
Quadratic Interpolation: An Example
NM Berlin Chen 11
Example 17.3
-
8/12/2019 NM2012S Lecture17 Polynomial Interpolation
12/24
Newton Interpolating Polynomials (3/3)
In general, an (n-1)th Newton interpolating polynomialhas all the terms of the (n-2)th polynomial plus one extra
The general formula is:
where
and the f[] represent divided differences
NM Berlin Chen 12
fn1 x b1 b2 x x1 bn x x1 x x2 x xn1
b1 f x1 b2 f x2,x1 b3 f x3,x2,x1
bn f xn,xn1,,x2 ,x1
-
8/12/2019 NM2012S Lecture17 Polynomial Interpolation
13/24
Divided Differences
Divided difference are calculated as follows:
Divided differences are calculated using divided
difference of a smaller number of terms:
NM Berlin Chen 13
f xi,xj f xi f xj
xixj
f xi,xj ,xk f xi ,xj f xj ,xk
xixk
f xn
,xn1
,,x2
,x1
f xn,xn1,,x2 f xn1,xn2,,x1 xnx1
-
8/12/2019 NM2012S Lecture17 Polynomial Interpolation
14/24
MATLAB Implementation
NM Berlin Chen 14
-
8/12/2019 NM2012S Lecture17 Polynomial Interpolation
15/24
Lagrange Interpolating Polynomials (1/3)
Another method that uses shifted values to express an
interpolating polynomial is the Lagrange interpolating
polynomial
The differences between a simply polynomial and
Lagrange interpolating polynomials for first and second
order polynomials is:
where the are weighting coefficients of thejth polynomial,which are functions ofx
NM Berlin Chen 15
3
332
321
312
23212
2221
211211
)()(2
)()(1
LagrangeSimpleOrder
xfLxfLxfLxfxaxaaxfnd
xfLxfLxfxaaxfst
niL
))((
))((
,))((
))((
,))((
))((
2313
2133
3212
3132
3121
3231
xxxx
xxxx
Lxxxx
xxxx
Lxxxx
xxxx
L
12
122
21
221 ,
xx
xxL
xx
xxL
-
8/12/2019 NM2012S Lecture17 Polynomial Interpolation
16/24
Lagrange Interpolating Polynomials (2/3)
The first-order Lagrange
interpolating polynomial may
be obtained from a weighted
combination of two linearinterpolations, as shown
The resulting formula based
on known pointsx1 andx2
and the values of thedependent function at those
points is:
NM Berlin Chen 16
2121
121
21
12
122
21
221
2
2
21
2
11
)(
,
)(
xfxx
xx
xfxx
xx
xf
xx
xxL
xx
xxL
xfLxfLxf
-
8/12/2019 NM2012S Lecture17 Polynomial Interpolation
17/24
Lagrange Interpolating Polynomials (3/3)
In general, the Lagrange polynomial interpolation for n
points is:
where is given by:
NM Berlin Chen 17
n
iL
n
ii
niin xfxLxf
11
n
ijj
ji
jni
xx
xxxL
1
-
8/12/2019 NM2012S Lecture17 Polynomial Interpolation
18/24
Lagrange Interpolating Polynomial: An Example
NM Berlin Chen 18
-
8/12/2019 NM2012S Lecture17 Polynomial Interpolation
19/24
MATLAB Implementation
NM Berlin Chen 19
-
8/12/2019 NM2012S Lecture17 Polynomial Interpolation
20/24
Inverse Interpolation (1/2)
Interpolation general means finding some value f(x) for somexthat is between given
independent data points
Sometimes, it will be useful to find thexfor which f(x) is a certain value - this isinverse interpolation
NM Berlin Chen 20
Someadjacent
points
of
f(x)
are
bunched
together
and
others
spread
out
widely.
Thiswouldleadtooscillationsintheresultingpolynomial.
-
8/12/2019 NM2012S Lecture17 Polynomial Interpolation
21/24
Inverse Interpolation (2/2)
Rather than finding an interpolation ofxas a function of
f(x), it may be useful to find an equation for f(x) as a
function ofxusing interpolation and then solve thecorresponding roots problem:
f(x)-fdesired=0 forx
NM Berlin Chen 21
-
8/12/2019 NM2012S Lecture17 Polynomial Interpolation
22/24
Extrapolation
Extrapolation is the
process of estimating a
value of f(x) that liesoutside the range of the
known base pointsx1,x2,
,xn
Extrapolation represents a
step into the unknown,
and extreme care should
be exercised whenextrapolating!
NM Berlin Chen 22
-
8/12/2019 NM2012S Lecture17 Polynomial Interpolation
23/24
Extrapolation Hazards
The following shows the results of extrapolating a
seventh-order polynomial which is derived from the first
8 points (1920 to 1990) of the USA population data set:
NM Berlin Chen 23
-
8/12/2019 NM2012S Lecture17 Polynomial Interpolation
24/24
Oscillations
Higher-order polynomials can not only lead to round-off errors
due to ill-conditioning, but can also introduce oscillations to
an interpolation or fit where they should not be
In the figures below, the dashed line represents an function,
the circles represent samples of the function, and the solid
line represents the results of a polynomial interpolation:
NM Berlin Chen 24
function)s(Runge' 251
12
x
xf