Sunteți pe pagina 1din 19

July 2013

Chapter 18
Interpolation

9 4444 260

Physics I/II, English 123, Statics, Dynamics, Strength, Structure I/II, C++, Java, Data, Algorithms,
. info@eng-hs.com 260 4444 9

Numerical, Economy
eng-hs.com, eng-hs.net

July 2013

You will frequently have to estimate intermediate values


between precise data points. The most common method
used for this purpose is polynomial interpolation. Recall that
the general formula for an nth order polynomial is
f ( x )=a 0+ a1 x + a2 x 2 ++a n x n

For n+1 data points, there is one and only one polynomial of
order n that passes through all the points. For example,
there is only one straight line (that is, a first-order
polynomial) that connects two points (figure (a)). Similarly,
only one parabola connects a set of three points (figure (b)).
Polynomial Interpolation consists of determining the unique
nth order polynomial that fits n+1 data points. This
polynomial

then

provides

formula

to

compute

intermediate values.

Although there is one and only nth polynomial that fits


n+1 points, there are a variety of mathematical formats in
which this polynomial can be expressed. We will describe
two alternatives that are well-suited for
computer implementation:
9 4444 260

Physics I/II, English 123, Statics, Dynamics, Strength, Structure I/II, C++, Java, Data, Algorithms,
Numerical, Economy
eng-hs.com, eng-hs.net

info@eng-hs.com 260 4444 9 .

July 2013

The Newton and the Lagrange polynomials.

18.1 Newtons Divided Difference Interpolating


Polynomials
Newtons divided difference interpolating polynomial is
among the most popular and useful forms. We will introduce
the first and second equations because of their simple
visual interpretation.
18.1.1 Linear Interpolation
The simplest form of interpolation is to connect two data
points with a straight line. Using similar triangles,
f 1 ( x ) f ( x 0 )
xx 0

f ( x 1 )f ( x0 )
x 1x 0

Which can be rearranged to yield


f 1 ( x )=f ( x 0 ) +

f ( x 1 )f ( x 0 )

The notation

x1x 0

f 1(x)

( xx 0)

designates that this is a first-order

interpolating polynomial. In general, the smaller the interval


between the data points, the better the approximation.

9 4444 260

Physics I/II, English 123, Statics, Dynamics, Strength, Structure I/II, C++, Java, Data, Algorithms,
Numerical, Economy
eng-hs.com, eng-hs.net

info@eng-hs.com 260 4444 9 .

July 2013

EXAMPLE 18.1 Linear Interpolation


Problem Statement:
Estimate

the

natural

logarithm

of

using

linear

interpolation.
First, perform the computation by interpolating between ln 1
=

and

ln 6 = 1.791759. Then, repeat the procedure, but use a


smaller interval from ln 1 to ln 4 (1.386294). Note that the
true value of ln 2 is 0.6931472.
Solution:
We use the previous equation and a linear interpolation for
ln(2)

from

x0 = 1 to x1 = 6 to give
f 1 ( 2 )=0+

1.7917590
( 21 )=0.3583519
61

9 4444 260

Physics I/II, English 123, Statics, Dynamics, Strength, Structure I/II, C++, Java, Data, Algorithms,
Numerical, Economy
eng-hs.com, eng-hs.net

info@eng-hs.com 260 4444 9 .

July 2013

Which represents an error of t = 48.3%. Using the smaller


interval

from

x0 = 1 to x1 = 4 yields
f 1 ( 2 )=0+

1.3862940
( 21 )=0.4620981
41

Thus, using the shorter interval reduces the percent relative


error

to

t = 33.3%. Both interpolations are shown in the next figure,


along

with

the

true

function.

18.1.2 quadratic Interpolation


The

error

in

Example

18.1

resulted

from

our

approximating a curve with a straight line. Consequently, a


strategy for improving the estimate is to introduce some
curvature into the line connecting the points.
If

three

accomplished

data

points

are

available,

with

this

can

be

9 4444 260

Physics I/II, English 123, Statics, Dynamics, Strength, Structure I/II, C++, Java, Data, Algorithms,
Numerical, Economy
eng-hs.com, eng-hs.net

info@eng-hs.com 260 4444 9 .

July 2013

second-order polynomial (also called a quadratic polynomial


or a parabola). A particularly convenient form for this
purpose is
f 2 ( x )=b 0+ b1 ( x x0 ) + b2 ( xx 0 )( x x1 )

(18.3)

Note that although the previous equation might seem to


differ from the general polynomial, the two equations are
equivalent. This can be shown by multiplying the terms in
the previous equation to yield
2
f 2 ( x )=b 0+ b1 xb1 x 0 +b 2 x + b2 x0 x 1b2 x x 0b 2 x x1

Or, collecting terms,


f 2 ( x )=a 0+ a1 x +a 2 x 2

where
a0 =b0b1 x 0 +b 2 x 0 x 1
a1=b1b 2 x 0 +b2 x1
a2=b2

Thus, eq. (18.3) and the general equation are alternative,



equivalent formulation of the
unique
second-order

polynomial joining the three points.
A simple procedure can be used to determine the values
of the coefficients. For b0, Eq. (18.3) with x = x 0 can be used
to compute
b0 =f ( x 0 )
9 4444 260

Physics I/II, English 123, Statics, Dynamics, Strength, Structure I/II, C++, Java, Data, Algorithms,
Numerical, Economy
eng-hs.com, eng-hs.net

info@eng-hs.com 260 4444 9 .

July 2013

which can be evaluated at x = x1 for


b1=

f ( x 1 ) f ( x 0 )
x 1x 0

Finally,
f ( x 2 )f ( x 1) f ( x 1 )f ( x 0 )

x2 x1
x 1x 0
b2=
x 2x 0

Notice that, as was the case with linear interpolation, b 1


still represents the slope of the line connecting points x 0 and
x1. Thus, the first two terms of Eq. (18.3) are equivalent to
linear

interpolation

from

x0

to

x1.

The last term, b2(x x0)(x x1), introduces the second-order


curvature into the formula.



EXAMPLE 18.2 Quadratic Interpolation
Fit a second-order polynomial to the three points used in
Example 18.1:
x 0=1 f ( x 0 )=0
x 1=4 f ( x 1) =1.386294
x 2=6 f ( x 2 )=1.791759
9 4444 260

Physics I/II, English 123, Statics, Dynamics, Strength, Structure I/II, C++, Java, Data, Algorithms,
Numerical, Economy
eng-hs.com, eng-hs.net

info@eng-hs.com 260 4444 9 .

July 2013

Use the polynomial to evaluate ln 2.


Solution:
Applying the previous equations yield
b0 =0
b1=

1.386294
=0.4620981
41

1.7917591.386294
0.4620981
64
b2=
=0.0518731
61
f 2 ( x )=0+ 0. 4620981 ( x1 )0.0518731 ( x1 ) ( x4 )
f 2 ( 2 )=0.5658444

which represents a relative error of t = 18.4%. Thus the


curvature introduced by the quadratic formula (next figure)
improves

the

interpolation

compared

with

the

result

obtained using straight lines in Example 18.1

General
form

18.1.3
of Newtons Interpolating Polynomials

The preceding analysis can be generalized to fit an n th


order

polynomial

to

n+1

data

points.

The

n th-order

polynomial is
9 4444 260

Physics I/II, English 123, Statics, Dynamics, Strength, Structure I/II, C++, Java, Data, Algorithms,
Numerical, Economy
eng-hs.com, eng-hs.net

info@eng-hs.com 260 4444 9 .

July 2013

f n ( x )=b 0+ b1 ( xx 0 ) ++b n ( xx 0 ) ( xx 1 ) ..(xx n1)

Data points can be used to evaluate the coefficients b 0, b1,


,

bn.

For a nth order polynomial, n+1 data points are required: [x 0,


f(x0)],
[x1, f(x1)], , [xn, f(xn)].
We use these data points and the following equations to
evaluate the coefficients:
b0 =f ( x 0 )
b1=f [ x1 , x 0 ]
b2=f [ x 2 , x 1 , x 0 ]

.
.
.
bn =f [ x n , x n1 , , x 1 , x 0 ]

where the bracketed function evaluations are finite divided


differences. For example, the first finite divided difference is
represented generally as
f [ x i , x j ]=

f ( xi ) f (x j )
x ix j

the

The second finite divided difference, which


represents

difference of two first divided differences, is expressed
generally as
9 4444 260

Physics I/II, English 123, Statics, Dynamics, Strength, Structure I/II, C++, Java, Data, Algorithms,
Numerical, Economy
eng-hs.com, eng-hs.net

info@eng-hs.com 260 4444 9 .

July 2013

f [ x i , x j , x k ]=

f [ x i , x j ]f [ x j , x k ]
xi x k

Similarly, the nth finite divided difference is


f [ x n , x n1 , , x 1 , x 0 ]=

f [ x n , x n1 , , x 1 ] f [ xn 1 , x n2 , , x0 ]
x nx 0

We can then substitute equations to yield the interpolating


polynomial
f n ( x )=f ( x0 ) + ( xx 0 ) f [ x1 , x0 ] + ( x x0 ) ( xx 1 ) f [ x 2 , x 1 , x 0 ]
++ ( x x0 ) ( xx 1 ) ( xx n1 ) f [ x n , x n1 , , x 0 ]

which is called Newtons divided-difference interpolating


polynomial.
It should be noted that it is not necessary that the data
points used in the previous equation be equally spaced or
that the abscissa values necessarily be in ascending order.


.
9 4444 260

Physics I/II, English 123, Statics, Dynamics, Strength, Structure I/II, C++, Java, Data, Algorithms,
Numerical, Economy
eng-hs.com, eng-hs.net

info@eng-hs.com 260 4444 9 .

July 2013

EXAMPLE

18.3

Newtons

Divided-Difference

Interpolating Polynomials
Problem Statement:
In Example 18.2, data points at x 0 = 1, x1 = 4, and x2 = 6
were used to estimate ln 2 with a parabola. Now, adding a
fourth

point

[x3

5;

f(x3) = 1.609438], estimate ln 2 with a third-order Newtons


interpolating polynomial.
Solution:
The third-order polynomial with n = 3, is
f 3 ( x )=b 0+ b1 ( xx 0 )+ b2 ( xx 0 )( xx1 )
+b3 ( xx 0 ) ( xx 1 ) (xx 2)

The first divided differences for the problem are


f [ x 1 , x 0 ]=

1.3862940
=0.4620981
41

f [ x 2 , x 1 ]=

1.7917591.386294
=0.2027326
64

f [ x 3 , x 2 ]=

1.6094381.791759
=0.1823216
56

The second divided differences are


f [ x 2 , x 1 , x 0 ]=

0.20273260.4620981
=0.05187311
61

f [ x 3 , x 2 , x 1 ]=

0.18232160.2027326
=0.02041100
54

9 4444 260

Physics I/II, English 123, Statics, Dynamics, Strength, Structure I/II, C++, Java, Data, Algorithms,
Numerical, Economy
eng-hs.com, eng-hs.net

info@eng-hs.com 260 4444 9 .

July 2013

Continue:
The third divided difference is
f [ x 3 , x 2 , x 1 , x 0 ]=

The results for

0.2027326(0.05187311)
=0.007865529
51

f [ x1 , x0]

f [ x2 , x1 , x0 ]

, and

f [ x3 , x2 , x1 , x0 ]

represent

the coefficients b1, b2, and b3, respectively, of the nth-order


polynomial equation. Along with b0 = f(x0) = 0.0, that
equation is
f 3 ( x )=0+ 0.4620981 ( x1 )0.05187311 ( x1 )( x4 )
+0.007865529( x1)(x4 )(x6)

which can be used to evaluate f3(2) = 0.6287686, which


represents a relative error of t = 9.3%. The complete cubic
polynomial is shown in the next figure.

Physics I/II, English 123, Statics, Dynamics, Strength, Structure I/II, C++,
Java,
Data,
Algorithms,
9 4444 260

Numerical, Economy
eng-hs.com, eng-hs.net

info@eng-hs.com 260 4444 9 .

July 2013

18.2 Lagrange Interpolating Polynomials


The Lagrange interpolating polynomial is simply a
reformulation of the Newton polynomial that avoids the
computation of divided differences. It can be represented
concisely as
n

f n ( x ) = Li ( x ) f ( x i )
i=0

(18.20)
where
n

Li ( x ) =
j=0
j i

where

xx j
x ix j

designates the product of. For example, the

linear version (n=1) is


f 1 ( x )=

xx 1
xx 0
f ( x0 )+
f ( x1 )
x0 x1
x 1x 0

And the second-order version is


f 2 ( x )=

Eq.

( xx 1 )( x x2 )
( x x0 ) ( xx 2 )
( xx 0 ) ( xx 1 )
f ( x0 )+
f ( x1 ) +
f ( x2 )
( x 0x 1 )( x 0 x2 )
( x1 x0 ) ( x 1x 2 )
( x 2x 0 ) ( x 2x 1)

(18.20)

can

be

derived

directly

from

Newtons

polynomial.

9 4444 260

Physics I/II, English 123, Statics, Dynamics, Strength, Structure I/II, C++, Java, Data, Algorithms,
Numerical, Economy
eng-hs.com, eng-hs.net

info@eng-hs.com 260 4444 9 .

July 2013

+ ( x x0 ) (xx 1)

( x2 x0 ) ( x2 x1 )

f ( x2 )




EXAMPLE
18.6

Lagrange

Interpolating Polynomials
Problem Statement:
Use a Lagrange interpolating polynomial of the first and
second order to evaluate ln 2 on the basis of the data given:
X0 = 1

f(x0) = 0

X1 = 4

f(x1) = 1.386294

X2 = 6

f(x2) = 1.791760

Solution:
The first-order polynomial can be used to obtain the
estimate at x = 2,
f 1 ( 2 )=

In

24
21
0+
14
41

similar

1.386294 = 0.4620981

fashion,

the

second-order

polynomial

is

developed as
9 4444 260

Physics I/II, English 123, Statics, Dynamics, Strength, Structure I/II, C++, Java, Data, Algorithms,
Numerical, Economy
eng-hs.com, eng-hs.net

info@eng-hs.com 260 4444 9 .

July 2013

f 2 ( 2 )=

( 24 ) (26) ( 21)( 26)


0+
( 14 ) (16) ( 41 ) (46)

1.386294

+(21)(24)
1.791760=0.5658444
( 61 ) (64)

As expected, both these results agree with those previously


obtained using Newtons interpolating polynomial.

:
:
:
Problem 18.1
Estimate

the

common

logarithm

of

10

using

linear

interpolation.
(a)

Interpolate between log 8 = 0.9030900 and log 12

= 1.0791812.
(b) Interpolate between log 9 = 0.9542425 and log 11
= 1.0413927.
For each of the interpolations, compute the percent relative
error based on the true value.

Solution
(a)
f 1 (10) 0.90309

1.0791812 0.90309
(10 8) 0.991136
12 8

9 4444 260

Physics I/II, English 123, Statics, Dynamics, Strength, Structure I/II, C++, Java, Data, Algorithms,
Numerical, Economy
eng-hs.com, eng-hs.net

info@eng-hs.com 260 4444 9 .

July 2013

1 0.991136
100 % 0.886 %
1

(b)
f 1 (10) 0.9542425

1.0413927 0.9542425
(10 9) 0.997818
11 9

1 0.997818
100 % 0.218 %
1

Problem 18.2

Fit a second-order Newtons Interpolating polynomial to


estimate log 10 using the data from problem 18.1 at x = 8,
9, and 11. Compute the true percent relative error.

Solution
First, order the points
x0 = 9 f(x0) = 0.9542425
x1 = 11
f(x1) = 1.0413927
x2 = 8 f(x2) = 0.9030900
b0 = 0.9542425
9 4444 260

Physics I/II, English 123, Statics, Dynamics, Strength, Structure I/II, C++, Java, Data, Algorithms,
Numerical, Economy
eng-hs.com, eng-hs.net

info@eng-hs.com 260 4444 9 .

July 2013

b1

1.0413927 0.9542425
0.0435751
11 9

0.9030900 1.0413927
0.0435751
0.0461009 0.0435751
8 11
b2

0.0025258
89
89

Substituting these values yields the quadratic formula


f 2 ( x) 0.9542425 0.0435751 ( x 9) 0.0025258 ( x 9)( x 11)

which can be evaluated at x = 10 for


f 2 (10) 0.9542425 0.0435751 (10 9) 0.0025258 (10 9)(10 11) 1.0003434



Problem 18.3
Fit a third-order Newtons interpolating polynomial to
estimate log 10 using the data from Problem 18.1

Solution:
First, order the points
x0 = 9 f(x0) = 0.9542425
x1 = 11
f(x1) = 1.0413927
x2 = 8 f(x2) = 0.9030900
x3 = 12
f(x3) = 1.0791812
The first divided differences can be computed as
f [ x1 , x 0 ]

1.0413927 0.9542425
0.0435751
11 9

9 4444 260

Physics I/II, English 123, Statics, Dynamics, Strength, Structure I/II, C++, Java, Data, Algorithms,
Numerical, Economy
eng-hs.com, eng-hs.net

info@eng-hs.com 260 4444 9 .

July 2013

f [ x 2 , x1 ]

0.9030900 1.0413927
0.0461009
8 11

f [ x3 , x 2 ]

1.0791812 0.9030900
0.0440228
12 8

The second divided differences are


f [ x 2 , x1 , x 0 ]

0.0461009 0.0435751
0.0025258
89

f [ x3 , x 2 , x1 ]

0.0440228 0.0461009
0.0020781
12 11

The third divided difference is


f [ x3 , x 2 , x1 , x 0 ]

0.0020781 (0.0025258 )
0.00014924
12 9



Continue:
Substituting the appropriate values into Eq. (18.7) gives
f 3 ( x) 0.9542425 0.0435751 ( x 9) 0.0025258 ( x 9)( x 11)
0.00014924 ( x 9)( x 11)( x 8)

which can be evaluated at x = 10 for


f 3 ( x) 0.9542425 0.0435751 (10 9) 0.0025258 (10 9)(10 11)
0.00014924 (10 9)(10 11)(10 8) 1.0000449

9 4444 260

Physics I/II, English 123, Statics, Dynamics, Strength, Structure I/II, C++, Java, Data, Algorithms,
Numerical, Economy
eng-hs.com, eng-hs.net

info@eng-hs.com 260 4444 9 .

July 2013

9 4444 260

Physics I/II, English 123, Statics, Dynamics, Strength, Structure I/II, C++, Java, Data, Algorithms,
. info@eng-hs.com 260 4444 9

Numerical, Economy
eng-hs.com, eng-hs.net

S-ar putea să vă placă și