pt4part 4 chapter15chapter 15 - caucau.ac.kr/~jjang14/nae/chap15.pdf · 2009-10-26 ·...
TRANSCRIPT
P t 4Part 4Chapter 15Chapter 15
P l i l I t l tiPolynomial Interpolation
All images copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
PowerPoints organized by Dr. Michael R. Gustafson II, Duke UniversityRevised by Prof. Jang, CAU
Chapter ObjectivesChapter Objectives
R i i th t l ti l i l ffi i t ith• Recognizing that evaluating polynomial coefficients with simultaneous equations is an ill-conditioned problem.
• Knowing how to evaluate polynomial coefficients and g p yinterpolate with MATLAB’s polyfit and polyval functions.
• Knowing how to perform an interpolation with Newton’s polynomialpolynomial.
• Knowing how to perform an interpolation with a Lagrange polynomial.
• Knowing how to solve an inverse interpolation problem by recasting it as a roots problem.
• Appreciating the dangers of extrapolation• Appreciating the dangers of extrapolation.• Recognizing that higher-order polynomials can manifest
large oscillations.g
IntroductionIntroduction• Suppose that you desired the density at a temperature not
included in the table below. In such a case, you would have to i l Th i ld h i h linterpolate. That is, you would have to estimate the values at the desired temperature based on the densities that include it.
• The simplest approach is to determine the equation for the p pp qstraight line connecting the two adjacent values and use this equation to estimate the density at the desired intermediate temperaturetemperature.
• Although such linear interpolation is perfectly adequate in many cases, error can be introduced when the data exhibit i ifi hi h d i l i i i dsignificant curvature. -> higher order interpolation is required.
T (C) (kg/m3) (Ns/m2) v (m2/s)200250300
0.7460.6750.616
2.57 10-5
2.75 10-5
2.93 10-5
3.45 10-5
4.08 10-5
4.75 10-5
400500
0.5250.457
3.25 10-5
3.55 10-56.20 10-5
7.77 10-5
Polynomial InterpolationPolynomial Interpolation• You will frequently have occasions to estimate
intermediate values between precise dataintermediate values between precise data points.
• The function you use to interpolate must pass• The function you use to interpolate must pass through the actual data points - this makes interpolation more restrictive than fitting.p g
• The most common method for this purpose is polynomial interpolation, where an (n-1)thp y p , ( )order polynomial is solved that passes through n data points:
f (x) a1 a2x a3x2 anx
n1
MATLAB version :
f (x) p1xn1 p2x
n2 pn1x pn
Determining CoefficientsDetermining Coefficients• A straightforward way for computing the• A straightforward way for computing the
coefficients is based on the fact that n data points are required to determine the npoints are required to determine the n coefficients. Hence, the polynomial coefficients can be found exactly using linear algebracan be found exactly using linear algebra.
• MATLAB’s built in polyfit and polyvalcommands can also be used - all that is required is making sure the order of the fit for n data points is n-1.
Example 15 1 (1/2)Example 15.1 (1/2)Q. Determine the coefficients of the parabola that passes through the last
three density values from Table 15.1
Solution)32
21)( pxpxpxf
Solution)
6160)( 300 11 .xfx 322
1 )300()300(6160 ppp.
4570)( 5005250)( 400
33
22
.xfx.xfx
322
1
322
1
)500()500(4570
)400()400(5250
ppp.
ppp.
525.0616.0
1400000,1601300000,90
2
1
pp
457.0
5 5.01500000,250
00000,60
3
2
pp
Example 15.1 (2/2)Example 15.1 (2/2)
>> format long
>> A = [90000 300 1; 160000 400 1; 250000 500 1];
>> b = [0.616 0.525 0.457]';>> b [0.616 0.525 0.457] ;
>> p = A\b
p = 0.00000115000000
0 00171500000000-0.00171500000000
1.02700000000000
027.1001715.000000115.0)( 2 xxxf
This polynomial can provide a means to determine intermediate points.For example, the value of density at 350C can be found as
567625.0027.1)350(001715.0)350(00000115.0)350( 2 f
p y
Polynomial Interpolation ProblemsPolynomial Interpolation Problemsnn
nn pxpxpxpxf
12
21
1)(
• One problem that can occur with solving for the coefficients of a polynomial is that the system to be
nn 121
inverted is in the form:x1
n1 x1n2 x1 1
x2n1 x2
n2 x2 1
p1p2
f x1 f x2
x2 x2 x2 1
xn1
n1 xn1n2 xn1 1
xnn1 xn
n2 xn 1
p2
pn1pn
f x2
f xn1 f xn
• Matrices such as that on the left are known as Vandermonde matrices, and they are very ill-conditioned -
n n n f n
, y ymeaning their solutions are very sensitive to round-off errors.
The issue can be minimized by scaling and shifting the data• The issue can be minimized by scaling and shifting the data.
Newton Interpolating PolynomialsNewton Interpolating Polynomials
• Another way to express a polynomial• Another way to express a polynomial interpolation is to use Newton’s i t l ti l i linterpolating polynomial.
• The differences between a simple ppolynomial and Newton’s interpolating polynomial for first and second orderpolynomial for first and second order interpolations are:
))(()()()()( d ti2)()()((linear) 1
NewtonSimpleOrder
21211211
bbbffdxxbbxfxaaxfst
))(()()()()(quadratic 2 21312122
3212 xxxxbxxbbxfxaxaaxfnd
Newton Interpolating Polynomials i i l i(Linear interpolation)
• The first-order NewtonThe first order Newton interpolating polynomial may be obtained from linear interpolation and similar triangles, as shown.
• The resulting formula based on k i t d d thknown points x1 and x2 and the values of the dependent function at those points is :at those points is :
f1 x f x1 f x2 f x1 x2 x1
x x1
• In general, the smaller the interval between the data points, the
2 1
Graphical representation of linear interpolationbetween the data points, the
better the approximation.
Newton Interpolating Polynomials Q d i i l i(Quadratic interpolation)
• The second-order Newton interpolating polynomialThe second order Newton interpolating polynomial introduces some curvature to the line connecting the points, but still goes through the first two points.
• The resulting formula based on known points x1, x2, and x3 and the values of the dependent function at those
i t ipoints is:))(()()( 2131212 xxxxbxxbbxf
f f f x3 f x2 f x2 f x1
f2 x f x1 f x2 f x1 x2 x1
x x1 x3 x2 x2 x1
x3 x1
x x1 x x2
Example 15.2Example 15.2Q. Estimate the natural logarithm of 2 using linear interpolation. First
compute it by interpolating between and . Then01ln 79175916ln compute it by interpolating between and . Then repeat the procedure using smaller interval from ln1 and ln4 (1.386294). Note:
01ln 791759.16ln
6931472.02ln
Solution) Using x1 = 1 and x2 = 6
3583519.0)12(16
0791759.10)2(1
f
Using x1 = 1 and x2 = 4,
4620981.0)12(0386294.10)2(1
f
The value εt are 48.3% and 33.3% respectively.
4620981.0)12(14
0)2(1 f
The value εt are 48.3% and 33.3% respectively.
Example 15 3Example 15.3Q. Use a second-order Newton polynomial to estimate
ln2 with the same three points used in Ex 15 2ln2 with the same three points used in Ex. 15.2.
Solution) 0)( 1 11 xfx
1.791759)( 61.386294)( 4
33
22
xfxxfx
0386294101 b 4620981.014
0386294.12
b
46209810386294.1791759.1
0518731.016
4620981.046
3
b
)4)(1(05187310)1(462098100)( xxxxf
The value ε are 18 4% > The quadratic formula improves the
)4)(1(0518731.0)1(4620981.00)(2 xxxxf
5658444.0)2(2 f
The value εt are 18.4%. -> The quadratic formula improves the error.
Newton Interpolating l i l l fPolynomials (General form)
• In general an (n-1)th Newton interpolatingIn general, an (n 1) Newton interpolating polynomial can be fitted to n data points.
• The general formula is:• The general formula is:
wherefn1 x b1 b2 x x1 bn x x1 x x2 x xn1
where b1 f x1 b2 f x2, x1 b3 f x3, x2, x1
b f
and the f[…] represent divided differences. bn f xn, xn1,, x2 , x1
Divided Differences• Divided difference are calculated as follows:
f x x f xi f x j f xi , x j xi xj
f xi , x j , xk f xi , xj f x j , xk
x x
Hi h d di id d diff l l t d i
xi xk
f xn, xn1,, x2 , x1 f xn, xn1,, x2 f xn1, xn2,, x1 xn x1
• Higher-order divided differences are calculated using divided difference of lower-order terms:
Graphical representation of the recursive nature of finite divided differences
Example 15.4 (1/2)Example 15.4 (1/2)Q. Estimate ln2 using a third-order Newton’s interpolating
l i l U th f ll i f i t 1polynomial. Use the following four points x1 = 1, x2 = 4, x3 = 6, and x4 = 5, [f(x4) = 1.609438].
Solution)Solution) ))()(())(()()( 32142131213 xxxxxxbxxxxbxxbbxf
462098100386294.1][ f 386294.1791759.1 4620981.014
0386 9.],[ 12
xxf 2027326.046
386294.1791759.1],[ 23
xxf
1823216.065
791759.1609438.1],[ 34
xxf65
02041100.045
2027326.01823216.0],,[ 234
xxxf
05187311.016
4620981.02027326.0],,[ 123
xxxf
45
007865529.015
)05187311.0(02041100.0],,,[ 1234
xxxxf
Example 15.4 (2/2)Example 15.4 (2/2)))()(())(()()( 32142131213 xxxxxxbxxxxbxxbbxf
xi f(xi) First Second Third
14
01 386294
0.46209810 2027326
-0.051873110 02041100
0.007865529465
1.3862941.7917591.609438
0.20273260.1823216
-0.02041100
)4)(1(05187311.0)1(4620981.00)(3 xxxxf 6287686.0)2(3 f)6)(4)(1(007865529.0 xxx
MATLAB ImplementationMATLAB Implementation
Lagrange Interpolating l i lPolynomials
• Another method that uses shifted value toAnother method that uses shifted value to express an interpolating polynomial is the Lagrange interpolating polynomialLagrange interpolating polynomial.
• The differences between a simply polynomial and Lagrange interpolating polynomials for first andLagrange interpolating polynomials for first and second order polynomials are:
Order Simple LagrangeOrder Simple Lagrange1st f1(x) a1 a2x f1(x) L1 f x1 L2 f x2 2nd f2 (x) a1 a2x a3x
2 f2 (x) L1 f x1 L2 f x2 L3 f x3 where the Li are weighting coefficients that are functions of x
2nd f2 (x) a1 a2x a3x f2 (x) L1 f x1 L2 f x2 L3 f x3
functions of x.
Lagrange Interpolating Polynomials (Linear)
• The first-order Lagrange g ginterpolating polynomial may be obtained from a weighted combination of two linearcombination of two linear interpolations, as shown.
• The resulting formula based on known points x and x and theknown points x1 and x2 and the values of the dependent function at those points is:
f1(x) L1 f x1 L2 f x2
L x x2 L
x x1L1 x1 x2
, L2 x2 x1
f1(x) x x2 f x1 x x1 f x2 f1(x)x1 x2
f x1 x2 x1
f x2
Lagrange Interpolating l i lPolynomials (cont)
)())((
)())((
)())((
)( 213132 fxxxx
fxxxx
fxxxx
f
• For quadratic formula, three parabolas would be used ith h i th h f th i t d
)())((
))(()(
))(())((
)())((
))(()( 3
2313
212
3212
311
3121
322 xf
xxxxxf
xxxxxf
xxxxxf
with each one passing through one of the points and equaling zero at the other two. Their sum would represent the unique parabola that connects the threerepresent the unique parabola that connects the three points.
• In general, the Lagrange polynomial interpolation for nge e a , t e ag a ge po y o a te po at o opoints is: fn1 xi Li x f xi
i1
n
where Li is given by: Li x x xj
xi x jj 1
n
xi x jj1ji
MATLAB ImplementationMATLAB Implementation
Inverse InterpolationInverse Interpolation• Interpolation general means finding some
l f( ) f h i b ivalue f(x) for some x that is between given independent data points.
• Sometimes, it will be useful to find the x for which f(x) has a certain value - this problem is called inverse interpolation.
• Rather than finding an interpolation of x as a g pfunction of f(x), it may be useful to find an equation for f(x) as a function of x using q ( ) ginterpolation and then solve the corresponding roots problem:pf(x)-fdesired=0 for x.
ExtrapolationExtrapolation• Two issues related to
polynomial interpolation –polynomial interpolation. extrapolation and oscillation.
• Extrapolation is the process of estimating a value of f(x) that g ( )lies outside the range of the known base points x1, x2, …, xn.
• Extrapolation represents a i h k (step into the unknown (curve
beyond the known region), and extreme care should beand extreme care should be exercised when extrapolating!
Example 15.6 (1/2)p ( / )Q. This table shows the population in millions of US from
1920 to 2000.
Year 1920 1930 1940 1950 1960 1970 1980 1990 2000
Population 106.46 123.08 132.12 152.27 180.67 205.05 227.23 249.46 281.42
Fit a seventh-order polynomial to the first 8 points (1920
to 1990). Use it to compute the population in 2000 by p p p y
extrapolation and compare your prediction with the actual
result.
Example 15.6 (2/2)Example 15.6 (2/2)
>> ts = (t-1955)/35;( )/>> p = polyfit(ts, pop, 7)p =Columns 1 through 8 -61.9393 -32.9356 147.0977 38.1565 -115.3518
6.4156 101.6934 166.3235>> p2000 = polyval(p, (2000-1955)/35)p2000 =175.0800
>> tt=linspace(1920,2000);>> l l( ( 1955)/35)>> pp = polyval(p, (tt-1955)/35);>> plot(t,pop,'o',tt,pp)
The polynomial seems to fit the data nicely from 1920 to 1990 H th l i l l t th1990. However, the polynomial plunges to the erroneous prediction in 2000 (outside). [175 vs. 281 (actual)]
OscillationsOscillations• Although “more is better” in many contexts, it is absolutely not true
for polynomial interpolation.p y p• 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 beinterpolation 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
h l f l i l i l irepresents the results of a polynomial interpolation:
I i i l d l i l b d• In most engineering contexts, lower-order polynomials can be used effectively to capture the curvature effects without oscillation.