You are on page 1of 22

Interpolation

Polynomial interpolation is an ancient practice, but the


heavy industrial use of interpolation began with cubic
splines in the 20th Motivated by practices in
the shipbuilding. and aircraft Industries, engineers Paul de
Casteljau and Pierre Bezier at rival European car manufac-
turers Citroen and Renault, followed by others at General
Motors in the United States. spurred the development of
what are now called cubic splines and Be.zier splines.
Although developed for aerodynamic studies. of auto-
mobiles, splines have been used for many applications,
Including computer typesetting. A re.volution in printing
was caused by two Xerox engineers who formed a com-
pany named Adobe and released the PostScript11-I Janguage
in .1984 .. It came to the attention of Steve Jobs at .A,pple
Corporation, who was looki ng for a way to control a newly-
invented laser printer. Bezier splines were a simple way to
adapt the same mathematical curves to multiple printer
resolutions.
Reality Reality Check 3 on page 188 explores how
E11eck PostScript constructs letters as Bezier splines.
E
fficiem ways of representing data are fundamental to advancing the undersr.anding of
scientific problems. At its most fundament:al, approximating data by a polynomial
is an act of data compression. Suppose that points (x . y) are taken from a given
function y = f (x) . or perhaps from an experiment where :c denotes temperarure and y
denotes reaction rate. A function on ,!lie real nuJ;llbers represents ao infinire amount of
information. Finding a polynomial through the set of datn means replacing the infonnation
with a rule that can be evaluated jn a finite number of steps. AJthough it is unrealistic to
expect the polynomial m ,represent the function exactly at new inputs x. it may be close
enough to solve practical pr.oblems.
This chapter introduces polynomial .interpolation and l:n.terpolation a.; convenient
tools for finding functions that _pass through given data points.
139

140 I CHAPTER 3 lnterpolatiqn
13.1 DATA AND INTERPOLATING FUNCTIONS
DEFif\JITION 3. 1
A function is said to interpolate a set of data points .if it passes through those ROints. Suppose
that a set of (x, y) data points has been collected, such as (0, 1), (2, 2), d (3, 4). There is
a parabola that passes through the three points, shown in Figure 3.1. This parabola i ~ ualled
the degree 2 interpolating polynomial passing through the three points.
y
Figure 3.1 Interpolat ion by
parabola. The points (0,1 ). (2,2),
and (3.4) are interpolated by the
function Pix)= !x
2
- }x + 1.
I
The function y = P (x) interpolates the data points (.q , Yt) , .... (xn, Yn) if. P(x;') = y; for
e.acb I ::.:; i ::.:; 11.
Note that P is required to be a function; that is, each value x corresponds to a single y
Tllis puts a restriction on the set of data points { (:r;, y;)} that can be interpolated-the x; ~
must be all distinct in order for a function to. pass through them. There is no such restrictior.
on they; 's.
Complexity
Why do we use polynomials? Polynomials are very often used for interpolation because
of lbeir straightforward mathematical properties. There is_a simple theory about when
an imerpolating polynomial of a given degree ex.ists for a given set of points. More
important, in a real sense, polynomials are the most .fundamenta] of functions for
digital computers. Central processing units usually have fast methods in hardware for
adding and multiplying floating points numbers, which are the operations needed to
evaluate a polynomial. Complicated functions cun be approximated by interpolating
polynomials in order to make tbern computable with these two hardware operations.
EXAMPLE 3.1
3.1 Data and Interpolating Functions I 141
To begin. we will look for an interpolating polynomial. Does uch a pol ynomial always
exi st? Assuming that the x-coordinmes of the points are distinct, the answer is yes. No
mauer bow many points are given, there is some polynomial y = P (x ) that runs lhrough aU
the point"S. This and several other f:1cts about interpolating polynomials are proved in this
section.
Interpolati on is the reverse of eval uati on. In polynomial evaluation (such as the nested
multiplication of Chapter 0) we are given a polynomial and asked to evaluate a y-value for
a &iven :c-value-that is. compute points lying on the cu.rve. Polynomial interpolation asks
l'or the opposite process: Gi ven these points. compute a polynomial that can generate them.
3.1.1 L9gra119e interpglati9Q
Assume that n data points (x1, Yl ) ... (xn, y
11
) are given, and that we would like to find
an tnterpolating polynomial . There is an expli'cit formula, called the Lagrange interpolating
formula. for writing down a polynomial of degree d = 11 - 1 that interpolates the points.
For example. suppose tim we are given three points (.tt, YJ ). (x2. Y2). (.t"3, )'3). Then the
polynomial
is the Lagrange interpolating polynomial for these points. First notice why the poi nts each
lie on the polynomial curve. When Xt is substiruted for x . the terms evaluate to Yt + 0 + 0 =
Yt The second and Lhi rd numerators arc chosen to disappear when Xt is ubstitutcd, and
the first denominator is chosen just so to balance the first denominator so that :v
1
pops out.
l t is si milar wben x2 :wd x3 are substiwted. When any other number is substituteu for x
we have little comrol over the result. But then. the job was onl y to interpolate at the lhree
poiots-lhat is the extent of our concern. Second, notice that the polynomial (3. 1) is of
degree two In the variable x.
Find an interpolating polynomial for the data points {0. 1). (2, 2) and (3. 4) in Figure 3.1.
Substituting into Lagrange's formula (3. 1) yields
p,
( )
(x - 2)(x- 3) .., (x - O)(x - ,3) (x - O)(x - 2)
\' - I + , I 4 - - --- -
2. - (0- 2)(0- 3) - (2 - 0)(2 - J) T (3 - 0)(3- 2)
= ( x
2
- 5x + 6) + 2 ( - ~ ) (x
2
- 3x) + + ( ~ ) (x
2
- 2x)
I , 1
= -x - -
2
x + l.
2
Check that P2(0) = I , P2(2) = 2 and P2(3) = 4.
In general. suppose that we are presented with 11 points (x1. YJ), . . . , (x
11
, Yn). For each k
between 1 and 11, define the term
142 I CHAPTER 3 Interpolation
THEOREM3.2
EXAMPLE 3.2
The interesting property of Lk is that Lk = J, while Lk (x 1) = 0, where x
1
is any of the
other data pointS. Then define the degree 11 - 1 polynomial
This is a straightforward generalization of the polynomial in (3.1) and works the same way.
Substituting Xk f.or x yields
so it works as designed.
We bave constructed a polynomiaJ of degree at most 11 - 1 that passes through any set
of n poin!S with distiuct x; 's. Interestingly, it is the only one.
1\lain Theorem ofPolynomlallnterpolation. Let (xt, Yl) ... (x, . y
11
) be n pointS in l.be
plane witb distinct x
1
Then there exists one and only one polynomial P of degree.n - 1 or
less that satisfies P (x;) = )'i for i = 1, ... , n.
Proof. The existence is proved by the explicit formula for Lagrange interpolation. To
sbo''' there is only one, assume 'for the sake of argument that there are two, say, P(x) and
Q(x), that have degree at most n - I and that both interpolate aJln points. That is, we are
assuming that P(.\J) = Q(.q) = Yl . P(x:.) = Q(x2) = )'2, ... P(xn) = Q(x,) = Yi: Now
define the new polynomiaJ H (x) = P(x) - Q(x). Clearly, the degree of H is also aLmost
n - 1. and. note that 0 = H(:q) = B (x2) = = H (xn) ; that is, H bas n distinct zeros.
According to the FundameotaJ Theorem of Algebra, a dcgreed polynomial can have at mosr
d zeros, unless it is the identically zero polynomiaJ. Therefore, H is the identicall y zero
polynomiaJ, and P(x) = Q(x). We conclude that tJ1ere is a unique P(x) of n - 1
interpolating then poiots (x;, )'I). D
Find the polynomial of degree 3 or less that interpolates the points (0, 2), (1, J), (2. 0),
and (3, -1).
Tl1e Lagrange form is as follows:
(x - l) (x - 2)(x - 3) (x - O)(x - 2)(x - 3)
Pf;r:) =
2
(0- 1)(0 - 2)(0 - 3) + l (1 - 0)(1 - 2)(1 - 3)
+
0
(x - O)(x - l )(x - 3) _
1
(,, - O)(x - l )(x - 2)
(2 - 0) (2- 1)(2 - 3) (3 - 0)(3 - 1)(3 - 2)
=

- 6x
2
+ 1 l x - 6) +

5x
2
+ 6:c)-

3x
2
+2x)
=-X +2.
Theorem 3.2 says that there existS exactly one interpolating polynomial of degree 3 or
less, but it may or may not be exactl y degree 3. ln Example 3.2, the data points are
colllnear, so the interpolating polyoomjaJ has degree 1. Theorem 3.2 implies l.bat there are
no interpol.ating polynomiaJs of degree two or three.ltn10y be already intuitively obvious
to you thal no parabola or cubic curve can pass through four collinear points, bul here is
the reason.
3. 1 Data and Interpolating Functions I 143
3.1.2 Newton's divided differences
The Lagrange interpolation method, as described in the previous section, is a consrructive
way to write the unique polynomial promised byTheorem3.2. It is also intuitive; one glance
explains why i t works. However, it is seldom used for calcttlntion because alternative meth-
ods result in IDO!e manageable and JeSS computationally CDmp[eX forms.
Newton's divided differences giyc a particularly simple way lo write the interpolating
polynom.ia.l. Given rz da.ta points, the resull will be a polynomial of degree at most rr - 1,
just as Lagrange form does. Theorem 3.2 says that it can be none other than the.same as the
Lagrange interpolating pol,ynomial. written in a disguised .form.
The idea of divided difference-s is fairly simple, but some notation needs co be mastered
first. View the datapoints as given by some function f, and list the data poiilrs in a table:
x, f (x,)
.\'2 fCi2)
Xn f (xn)
No\V define (be divided differences, which are the reaLnumbers
= f(Xf;)
l
f[.\"Hd - flxkJ
f [Xk X.C+ I,, = ::......;._:_:__:__.:.._:___;;,
Xk'fl - 'Xk
)
. f[XJ.:+l Xk+21 - f[Xk Xk+J]
flxk XN 1 X1: 72 = ::......;.....:....:;____:_;___...:......;;___....:.....;..
Xk+2- .Xk
j[Xk+l -"k+2 Xk.73) - Xhl Xk+2]
j[X,i; XkT I Xk+2 XJ: +3] =
Xk+3 - ;q
(3.2)
and so on. These nmnbers are the coefficients of rbe imerpolaling polynomial for rhe data
poiniS_, which is gi'Ven by the Newton's divided differen ce formula
P (x) = f[xi] +f[;q xz](x - xr )
+J[xr X2 X3)(x- Xt)(.X - X2)
+./(X! X2 X'J- X4](x - xt) (x- X2) (X- X3)
+ ...
+ /Ltt .. Xn) (:t - XJ) .. (X - Xn-d
A proof of the fact that the polynomial interpolates then data points is given in Section 3:2.2.
Notice that the divided difference formula gives the interpola.ting polynomial as a nested
polynomial. It is automatically ready to be eval uated in an efficient way.
Newton's Divided Differences
Given x = [x1 . . .. , x,,], y = LYt ... y,,]
for j = 1. ... , 11
f[x j ] = Yj
end
144 I CHAPTER 3 Interrelation
EXAMPLE 3.3
for i= 2, . . . , 11
for j = 1, ... , n + 1 - i
f(Xj .. XJ+i-IJ = (f[x
1
..,.t . Xj+t-1)- /[Xj . .. Xj+;-:!))/(XJ+i-1- Xj)
end
end(+
The interpolating polynomial is
n
P(x) = L f[.q ... x;](x- x,-) (x- Xi-1)
i=!
The recursive definition of the Ncwtoos divided differences allows arrangement into
a convenient rable. For three points the table has the form
.q f[xt]
rrx, .Q]
X2
f[x2 ]
flx t. .\"2 X3]
J[x2 x3)
.t3
J[x3]
The coefficients of tbc polynomial (3.3) can be read from the top edge of tbe triangle.
lfse divided differences to find the interpolating polynomial passing through the points
(0, 1), (2, 2), (3, 4).
Applying the defi nitions of divided differences leads to the foll owing table:
0
l
2
1
2 2
2
2
3 4
This table is computed as follows: After writing down the x and y coordinates in separate
colum.ns, calculate the next columns, left to ri ght, as divided differences. as in (3.2). For
example.
4 -2
= 2.
3-2
After completing the divided difference u:iangle, the coefficients of the polynomial I.
1/2, 1/2 can be rend from the top edge of the table. The interpolating polynomial can be
wrin(m as
1 l
P(x) = I + -(x- 0) + ) (x - O)(x - 2).
2 -
or, in nested form,
P(x ) = 1 + (x- 0) ( ~ + (x - 2) ~ ) .
EXAMPLE 3.4
EXAMPLE 3.5
3.1 Data and Interpolating Functions J 145
The base poims for me nested fonn (see Chapter 0) are r1 = 0 and r 2 = 2. Alternatively,
we could do more algebra and write the interpolating polynomial as
1 I 1 ., I
P(x) = 1 +
2
x +
2
x(x- 2) =
2
,..--
2
x + 1,
matching the Lagrange .interpolntion version shown previously.
Using the ilivided difference approach, new data points that after computing rl1e
original interpolating polynomial can be easily added.
Add the fourth data point ( I, 0) to the list in Example 3.3.
We can keep the calculations that were already done.and just add :1 new bonom row to
the triangle:
0
1
2
I
2 2
2
2.
l
-2
..,
.) 4 0
2
0
The result is one new term to add .to the original polynomial P2(x). 'Reading .from the top
edge of the triangle, we see that the new degree 3 interpolating polynomjal is
P3(x) = I + - 0) + O)(x- 2)- O)(x- 2)(x- 3).
2 2 2
Note that P3(.t) = P2(x) - t(x - O) {x - 2)(x - 3), so the previous polynomial can be
reused as part of the new one.
[tis interesti ng to compare the extra work necessary to add a new poim to the Lagrange
fonnulation versus the divided difference fonnulation. Tho Lagrange polynomial must be
restarted from the beginning when a new point is acldeo: none of the previous calculnlion
can be used. On the other hand. in divided difference form, we keep the earlier work and udd
one new term to the polynomial. Therefore, the divided difference appr.oach bas a real-time
updating" property that the Lagrange form lacks. ').'he operation counts for Lagrange and
divided difference jn[erpolati on are compared in Exereise 15.
Use Newton's cjivided differences to lind t11e lnterpolalingJ)Oiynomial passing through
(0, 2), (I 1 l), (2, 0), (3, - I).
The divided difference triangle i s
0 2
- 1.
0
- I 0
2
Q,
0
- I
3 - 1
146 I CHAPTER 3 Interpolation
EXAMPLE 3.6
Reading off the we find that the inrerpolating polynomial of degree 3 or
less is
P(x) = 2 + (-l )(x- 0) = 2- x.
agreeing with Example 3.2, but arrived at with much less work.
3.1.3 How many degree d polynomials pass through n points?
Theorem 3.2. the Main Theorem of polynomial interpolation, answers this question if
05;d sn- I. Given n = 3'points (0, 1).(2.2),(3,4) . t.here is one interpolating poly-
nomial of degree 2 or less. 'Example 3. 1 shows that it is degree 2, o there are no degree 0
or I interpolating polynomials through the three data points.
How many degree 3 polynomials interpolate lhc same three points? One \..,.ay to con-
structsuch a polynomial is clear from the previous discussion: Add a fourth point. Extending
the Newton divided difference triangle gives a new top eocfficicnt.ln Example 3.4. the poinl
( I , 0) was added. The resulting polynomial,
1
P3(x) = P2(x) -
2
(x - O)(x - 2) (x- 3),
(3.4)
passes through the three points in question, in addition to the new point ( 1, 0) . So there
is at least one degree 3 polynomial passing through our three ori ginal points (0.1), (2. 2) .
(3,4).
Of course. tbere are maily different ways we could ha\'e chosen tbe fourth point. For
example. if we keep the same x
4
= 1 and simply change .\'.t from 0. we must get a differ-
ent degree 3 interpolating polynomial. since a function can only go through one y value
at x
4
. Now we know there are iniirutely many polynomials that interpolate the three points
(Xt ,)'J). (x2, )'?.) . (x3, )'3). since for any fixed X4 tbere are infinitely many ways y
4
can be
chosen. each giving a djffere.nrpolynomial. n,h line of thinking shows that. given n data
points C.rr, y;) with distinct x;, there are infinitely many degr-ee 11 polynomials passing
through tbern.
A :o.econd loo)< at (3.4) suggests a more direct way to produce interpolating polynomial s
of degree 3 through three points. Instead of adding a fourth point to generate a new degree 3
coefficient. why not j ust pencil in a new coefficient? Does the result interpolate the original
Lhree points?Ycs. because P2(x) does, and the new term evaluates to zero at x.1, x2, andx3. So
there is really no need to consLrUct the extra !\e'.\'too's divided differences for this purpose.
Any degree 3 polynomial of the form
with c f:. 0 will pass through (0, l). (2. 2). and (3, -I). 'This technique will also easily con-
sLruct (inftnitely many) polynomials of degree::=._ 11 for 11 data points. as illustrated in
the next example.
How many polynomials of each degree 0::: d 5; 5 pas t11rough the points (-I. -5).
(0, -I), (2.1) . and (3. U)?
3. 1 Data and Interpolating Functions I 147
The Newton' divided difference rriangle is
-1 -5
4
0 - 1 - 1
2 3
10
3 II
So there are no interpolating polynomials of degree 0. I. or 2. and the single degree 3 is
P3(x) = -5 + 4(x + I) - (x + l )x + (x + l ) x(x - 2) .
There arc infinitely many degree 4 interpolati ng polynomials
= P3(x) + c1 (x + l )x (x - 2)(.\'- 3)
for arbi trary ct :;!: 0. and infinitely many degree 5 interpolating polynomials
Ps(x ) = P3(x) + c2(x + l )x
2
(x - 2)(x - 3)
for arbitrary c2 :;!: 0.
3.1.4 Code for interpolation
Tbe MATLAB program newt.dd . m for computing the coefficients follows:
3 . 1 Newton Div1ded In:erpolation Method
%Computes of im:erpolaLing polynomial
%I.:1put : x and y are veccors con taining t he :< and y coordinates
% c: n da=a
coe::lcie;.cs c o= r.ested to=rn
%Use th nest . rn Lo eva lt.:ac.e !.n:er;:>olat.ir:g ;:>olyr.omial
: unction c=newcdd(x,y , n)
::or j::l : n
v(j,l ) =ylj ) ; \ y columr. of Newton
end
for i=2 : n % For column i,
Ear j=l : o+l-i % Eill in column from top co boccom

end
end
:or i=l : n
c(i)=v(l,i) ;
end
Read cop of
% for oucput coefficients
This program can be applied to the data points of Example 3.3 to return the coefficients
I. 1/ 2, 1/ 2 found above. The. ccoeffi cients can be used in the nested multiplication program
1.0 evaluate the interpolating polynomial at various x-val ues.
For example, the MAn.AB code segmem
x0=[0 2 3];
y o= r 1 2 4J:
148 I CHAPTER 3 Interpolation
( xO, yO, J I ;
X:0:.01 : 4 ;

'o',x, y )
will result in the plot of the polynomial shown in Figure 3. 1.
Now that we have !vLm .. AB code for finding the coefficients of the interpolating poly-
nomial (newtdd. :n) and for evaluating the polynorruaJ (nest . m). we can put them
tog_ether to build a polynomial interpolation routine. The progran1 clickinterp .m
uses MATLAB's grapbics capability to plot the interpolation polynomial as it is being cre-
ated. Sec Figure 3.2. MATL<\B's mouse input comm3Jld g input is used to facilitate data
entry.
3
\
\
2
0
\ I / \
\t/ \ I
\ I
I \i
- 1
-2
0 2
Figure 3.2 Interpolation Program
3.2 using mouse i nput. Scrernshol
of Mt.TLAB code - _ -, .
wfth four input data points.
I
3
%P:r:ogra.T. 3 . 2 . clicki:1terp. rn Polynomial Interpolacion Program
%Left click in MATLAB figt.:re ,.,indoll to locate data point .
% Continue, co add more
% ?..lght -click t o terminate program.
xl=-3;xr=3;yb=-3;yt:3;
plot([ >: l xr),[O OJ. 'k', [ O Oj.(}rbytl.'k ' );grid on;

bu.tt:on=l ; k=O ; % councer k
while(button -: 3) % i : right click, :erm:nate
!>:ne . .,r,yne.-., button) c: gi:1pUt: (1) ; % get one mouse click
if := 1 % click is a left click
% k counts clicks
xlist(k)=xne . ;; ylist (k):ynew; % add ne\,, point t:o the list
c=newtdd(>::ist , ylist, k) ; % get interpolation coeffs
x=xl:.Ol:x=; t define x coordinates of Cl.lrve
y:nest (k- l,c,x, xlist) ; \get y coordi:1at:es c:
plot ( >:list,yl:.st, ' o' .x.y, (xl xr j, iO.OL 'k', {0 0), {yb yt), 'k');
axis ( [xl xr yb yt) ) ; grid on;
end
end
S P ~ O N
EXAMPLE 3.7
3. 1 Data and Interpolating Functions I 149
Compression
This i our first em:ounrer with the concept of compression in numerical analysis. At
first, interpolation may not seem like compression. After all. we taken points as input
and deliver 11 coefficients (of the interpolati ng polynomial) as output. What has been
compressed'!
Think of the data points as coming from somewhere, say as representatives
chosen from lhe multirudeofpoints on a curve y = f (.r). Tbc degree" - 1
polyoomial, charucterized by n coefficients, is a compressed version" of f(x)., and
may in some cases be used as a fairly simple representative of f(x) for computational
pLtrposes.
For example. what happens when the sin button is pushed on a calculutor? The
calcul ator has hardware to add and multiply, but how does it compute the sin of a
number? Somehow the operation must reduce to the evaluation of a polynomial. which
requires exactly those operations. By choosing d:.tt:l points lying on lhe sine curve, an
interpolating polynomial can be calculated and stored in the calculator as a compressed
version of the sine function.
This type of compression is "lossy compression: meaning that there will be
error involved. since lhe sine function is not actually a polynomial. How much error is
made when a function f(x ) is replaced by an interpolating polynomial is the subject of
the next seCLion.
3.1.5 Representing functions by approximating polynomials
A major use of polynomiallnterpolalionis to replace evaluation of a complicated function
by evaluation of a pol ynomial which .involves ouly elementary computer operations like
addition, subtraction. and multiplication. Think of thi s as a form of compression: Something
complex is replaced \vi th something simpler and computable. with perhaps some loss in
accuracy that we will have to analyze. We begin with an example from trigonometry.
Interpolate the functi on f(x') = sinx at 4 equally-spaced points on [0, rr / 21.
Let's compress the sine function on the interval fO, rr /2]. Take four data points at
equall y spaced points and .form the divided difference triangle. We list the vhlues to four
correct places:
0 0.0000
0.9549
7i/ 6
0.5000 -0.2443
0.6691 -0.1 139
2rr/ 6 0.8660 -0.4232
0.2559
3rr / 6 1.0000
150 I CHAPTER 3 Interpol ation
The degree 3 interpolating polynomial is therefore
P
3
(x) = 0 + 0.9549x- 0.1443x(x- tr/ 6)- O.IL3.9x(x - tr/ 6)(x- rr/ 3)
= 0 + x(0.9549 + (x - tr / 6)( - 0.2443 + (x - 1f /3)( - 0. 1139))) . (3.5)
This polynomial is graphed together with the sine function in Figure 3.3. At this level of
resolution, P3(x) and sinx are virtually indisti.nguishablt: on the interval[O.tr/ 2]. We
have compressed the infinite amount of infom1alion held by the sine curve into a few
stored coefficients and the ability to perform the 3 adds and 3 multiplies in (3. 5).
How close are we to designing the sin key on a calculator? Certainly we need to handle
inputs from the entire real line. But due to the symmetries of the sine function, we have done
the hard part. Tbc interval [0, rr / 2] is a so-cal led fundamental domain for sine, meaning
that an inpm from any other interval can be referred back to it. Given an input x from
[rr / 2. rr]. say. we can. compute sinx as sin(:r - x), since si n is symmetric about x = JT /2.
Given an input x frori1 [rr. 2JT ], sinx = - sin(2JT - x) due to antisymmerry about x = tr .
Finally. because sin repeats its behavior on the interval [0, 2rr] across the entire real line,
we can calculate for any inpul by firsl reducing modulo 2rr. This leads to a straightforward
dcS"igo for the s LT"J key:
lit?r:og:::am 3 . 3 3uildi:<g a sin calcular-or key, atr:empt H
%.:r..ppr-o:.:imaces si:1 cur Je with degree 3 poiyncmial
% {Caution: do n oL use co build
% at: least:. unt.il we have discussed a.ccu:-acy. )
%Input : x
%Out. put : io:-: =.o::: s 'i :1 ( :<}
unccion y=sinl!x)
Lhe polynomial and
% score coefficients
b=pi (0 : 3l /6; yb=sin (b) ; % b hol es base point:.s

%For each input x, move x co Lhe domain and evaluate
% the i nterpolating polynomial
s=l; %'Correct the sign of
Xl=mod (x, 2"" pil ;
if xl>pi
xl = 2 pi-xl ;
5 = -1 ;
e.::!d
:Lf xl > pi /2
xl = pi-xl ;
end
y = s nest{J , c ,xl, b) ;
Most of the work in Program 3.3 is tO place x into the fundamental domain. Then we
eval uate the degree 3 polynomial by nested multiplication. Here is some typical output from
Program 3.3:
3. 1 Exercises
3.1 Data and Interpolating Functi ons I 15 1
):
,l
Fi gure 3.3 Degree 3 interpolation
of sin x. The inrerpolation polynomial'
(5old curve:) Is plotted alohg with
y= sin:<. Equally-spaced
nodes .are at 0. -:r /6, 2:r/6, and 3;r/ 6.
The approximation is very close
b.: tween 0 and ::r / 2.
X
I
sinx P3(x) error
1 0.8415 0.84.11 0.0004
2 0.90Q3 0.9l02 0.0009
3' 0.1411 0.1428 0.0017
4 - 0.7568 -0.7557 o.oou
14 0.9906 0:9928 0.0022
1000 0.8269 0.8263 0.0006
This is not bad for the first try. The error i s usualiy under .I percent In order to get enough
correct ctigits to fill the calculator readout. we' llneed to knowa little more
error, the topic of the next section.
1. Use Ll].grange interpolation 1.0 find a polynomial that passes Lhrough ilie points.
(:a) (0, 1), (2, 3), (3, 0)
(b) (- 1.0), (2, 1), (3.1), ;(5, 2)
(c) (0, -2), (2, 1), (4 , 4)
2. Ose Newton's divided to find the polynomials of.the points in
Exercise I, and verify agreement with the interpolating polynomial.
3. How many degree d pol ynomials pass Lhrougb the four points (-1 ,3). (l , J ) . (2.3), (3, 7)?
Write one down if possible. (a) d = 2 (b) d = 3 (c) d = 6
4: (a) Find a poLynomial P(x) of degree 3 or less whose .graph passes through the points
(0, o), (1, 1), (2, 2) , {3, 7). (b) Find two other polynomials (of any<legree) 'thar pass through
these four points. (c)Decjde whelhe.r there eXists. a polynomial P (;!:) Of degree 3 odess whose
.graph passes througb the points (0, 0), (1, 1), (2, 2): (3, 7), and (4, 2).
152 I CHAPTER 3 Interpolation
5. (a) Find a polynomial P(x) of degree three or le.ss whose graph passes through the four data
points ( -2, 8). (0. 4), ( I. 2) , (3, -2). (b) Dt: scribe any other polynomials of degree 4 or Jess
which pass througb the four points in pan (a).
6. Writ,e down a pnl ynomia.l of degree exactly 5 that jmerpolates the four points
{1. 1) , (2, 3). (3. 3) , (4, 4).
7. Fi nd P(O) , where P (x) is tbe degree 10 polynomial that is zero at x = I , ... , 10 and satisfies
P(J2) = 44.
8. Let P(x ) be the degree 9 polynomial that takes the \'a.IUc 112 at x = I. takes the value 2 at
x = I 0, and equals zero for x = 2, ... , 9. Calcul ate P (0).
9. Give an example of the following. or explain why oo such example exists. (a) A degree 6
polynomial L(x) that is zero atx = 1. 2,3. 4. 5. 6 and.equal to 10 at x = 7. (b) A degree 6
polynominl L(x) that is zero atx = 1. 2.3.4,5.6. equal to 10 at x = 7. and equal to 70 at
X =8.
10. Let P (x) be the degrc.-e 5 polynomial that rakes t11 e value 10 at x = 1. 2. 3.4, 5 and the va.l uc 15
ar x = 6. Find P(7).
11 . Let P,. P1. !'3, ~ m d P
4
be four different points lyi ng on a parabola y = ax
2
+ bx +c. How
many cubic (degree 3) polynomials pass through those four points? Explain your answer.
12. Can a degree 3 polynomia.l intersect a degree 4 polynomia.l in exactly five points? Explain.
13. The cstimared mean atmospheric concentration of carbon dioxide in earth s atmosphere is
given in t11e table that follows, in parts per million by volume. Find the degree 3 interpolating
polynonual of the data and u.e it to estimate !J1e C02 concentration in (a) 1950 and (b) 2050.
(Tbe acrual concentration in 1950 was 310 ppm.)
year C02 (ppm)
1800 280
1850 283
1900 291
2000 370
14. The expected lifetime of an industrial fan when operated at the listed temperature is shown in
the table tbat follows. Estimate the lifetime at 70"'C. by using (a) the parabola from the last
three data points (b) tbe degree 3 curve using alJ four points.
temp. (C) brs. (xl 000)
..,-
-:>
95
4'0 75
50 63
60 54
15. Count the number. of multiplications uod additions necessary to evaluate the imerpo.lating
polynomial through 11 data points in (a) Lagr-dnge fonn (b) Newton's divided difference fom1
(using nested multiplication to evaluate).
3.2 Interpolation I 153
3.1 Computer Probl ems
1. Appl}' the following world population figures to estimate the 1980 population. using (a) the
straight line through the 1970 and 1990 estimates; (b) the parabola through the 1960, 1970. and
1990 estimarcs; and (c) the cubic curve through all four data points. Compare w11h the 1980
estimate of +15258-1592.
year population
1960 3039585530
1970 3707475887
1990 5281653820
2000 6079603571
2. Write u version of Program 3.2 tJ1at is a ivi.AlL>\B functi on, whose inputs x nnd y are equal
length vectors of data points. and whose output is a plot of the interpolating pOl}'llOmiuJ. In this.
way. the points can be entered more accuratdy than by mouse input. Check your program by
repli cating Figure 3.2.
3. Write a MA1'LAB function poly i r.r.: erp . m that takes 3S input n set of (x. y) interpolating
points and another xo, and outputs YO the value of the intc:rpolating polynomial at .co. The ftrst
line oithe fileshouJd be =t:nctio:1 yO =poly in::erp (x, y . xO), where x andy are
input vectors of dara points. Your function may call ne.,r.:dd from Program 3.1 and nesc
from Chapter 0. and may be st:rucrurcd similarly to Progr:un 3.2. but without the graphics.
Demonstrate tJmt your function works.
4. Remodel the s:..r.l calculator key in Program 3.3 to build cosl. a cosine key that foUows the
s:1me principle . First decide on the fundamental domain for cosine.
5. (:1) Usc the addition fonnulas for sin and cos to prove that tan(rr / 2- x ) = 1/ tnn.t. (b) Show
that ro. rr /41 can be used as a fundamental domain for tan.t . (c) Design a tangent key, followi ng
the principles of Program 3.3, using degree 3 polynomial interpolation on this fundamental
domain. (d) Empirically calculate the maximum error of the tangent key in [0. rr /4).
3.2 . l INTERPOLATION ERROR
The uccurocy of our sin calcutamr key depends on the npproximntion in Figure 3.3. Row
close is it? We presented a tabte indicating that, for a few examples, the fir t tWO digits are
fairly reliable, but after that the digits are not always correct. In this we investigate
ways to measure this error nnd determine how to make it smaller.
3.2.1 Interpolation error fqrmula
Assume thnt we start wi th a function y = f(x) and take data points from it to build an inter-
polating polynomial P(x) . as we did with f(.r:) = sinx in Exnmple 3.7. The interpolation
er ror at xis f(x)- P(x) , the difference between the original function that provided the
data points and the interpolating polynomial. nt x. The interpolation error is the
vertical di tance between the curves in 3.3. The next theorem l!ivcs a formula for
-
1 54 I CHAPTER 3 Interpolation
EXAMPLE 3.8
lbe interpolation error that is usually impossible to evaluate exactly. bm often can at least
lead to an error bound.
Assume that P (x) is the (degree n - 1 or less) interpolating polynomial fitting t.be n points
(xt . )'1 ), ... , (x
1
" )'n). The interpolation error is
f(x) - P (x ) = (x - Xt )(:r- ;r:! ) ... (x - Xn) ! (")(c). (3.6)
n!
where c lies between the smallest and largest of the numbers x, XJ, .. , x
11

See Section 3.2.2 for a proof of Theorem 3.3, We can use the theorem to assess the
accuracy of the sin key we buill in Example 3.7. Equati on (3.6) yields
. ) (x - 0) (x - i) (x - 1-) (x - %)
11
,
smx - P(x =
41
- f (c).
where 0 < c < rr / 2. The fourth derivative /
1111
(c) =sin c varies from 0 to 1 in this range.
At worst. I sin cl is no more than l. so we can be assured of an upper bound on interpolation
error:
l
(.r - 0) (x- !!.) (x- !!.) (x- ?)I
jsinx- P(x )l
6
24
3
' Il l.
Au = I. the worst-case error is
I sin 1- P(l )l O){l-

!)Il l 0.0005348. (3.7)


This is an upper bound for the error, since we used a "worst case" bound for t.be fourth
derivative. Note that the actual error al x = I was .0004, which is within the error bound
given by {3.7). We can make some conclusions on the basis of t11e form of the interpolation
error fonnula. We expect smaller errors when xis closer to the middle of the interval of xi s
than when it is near one of the ends, because there will be more small terms in the product.
For example, \ve compare the preceding error bound to the case x = 0.2, which is near the
left end of the range of data points. In this case, the error fonnula is
I
< 2- o) ( 2- it) ( 2- .!!.) (' -


3
- -
about six times larger. Correspondingly. the acntal error is larger. specifically.
lsin0.2- P(0.2)1 = 10. 19867- 0.200561 = 0.00189.
Find an upper bound for tile-difference at x = 0.25 and x = 0.75 between f(x) = ec and
the polynomial that interpolates jt at the points -1. -0.5. 0. 0.5. 1.
Construction of the interpolating polynomial. shown in Figure 3.4. is not necessary to
find the bound. The interpolation error formula (3.6) gives
(x + I) (x + ! ) x (.r - (x - I) (SJ
f(x)- = f (c) ,
5!
3.2 Interpolation Error I 155
}'
Figure 3.4 Interpolating polynomial
for approximating f(x) =ex. Equally
spdced base poinrs - 1. -0.5, 0, 0.5, 1.
The. solid curve Is the inrerpolating
polynomial.
where - I. < c < 1. The fifth derivative is j C
5
) tc) = ec. Since ex is increasing with x, its
maximum is at the right-hand end oftbe interval. so lf (S)I e
1
on [-I, 1]. For
- I x =:; 1, the error formula becomes
(x + 1) (:c + } ) x (x - (x - L)
- p.J (x ) I < - " I - I!.
) .
At x = 0.25. the interpolation error has the upper bound
0.25 - ( 1.25)(0.75)(0.25)(-0.25)(-0.75)
le -
120
e
::::::: .000995.
At x = 0. 75, the interpolation error is potentially larger:
o?s )I ( 1.75)( 1.25)(0.75)(0.25)(0.25)
le - :5 "JQ e
L
;:::::: .002323.
Note again tbatthe interpolation error will tend to be smaller close Lo lhe center of Lhe
interpolation interval.
3.2.2 Proof of Nevyto_n form error formula
In this section we explain tbe reasoning behlud two importaut facts used earlier. First we
establish the Newton's di vided difference form of the interpolating polynomjal, and then
we prove the interpolation error fonnula.
RecaiJ what we know so far. If x1 ... x, arc It distincr pointS on the real line and
Yt, .... Yn are arbitrary, we know thcrc is exactly one (degree at most n - t ) interpolating
polynomial P, _t (x) for these points. We also know that tbe Lagrange interpolating formula
gives such a polynomial.
The only lhing we don' t know is whether the Newton's divided difference fonnula also
gives us an interpolating polynomial. Once we prove that it does in Theorem 3.7, we wilJ
156 ] CHAPTER 3 Interpolation
!JMMA 3.4
DEFINITION 3.5
LEMMA 3.6
know it must agreewilb version. We start by finding aformuJo for the degree
11 - I coefficiem of Pn-1, and then specialize to the Newton form.
Consider two other interpolating polynomials: Pn-2 which imerpolarcs x
1
, .. Xn- L.
and Q
11
-2, which imerpolares x 2 ... Xn. The following relati on holds berween them:

Proof. Since the difference between the two sides is a polynomial of degree ar most
n - l, it suffi ces to prove thaL the rwo sides are equal at any n distinct points. Then, by
the FundamenU':I.l Theorem of Algebra, rhe difference must be the identically zero poly-
nomial. The 11 points we choose are t:he n interpolation points. At x = x
1
, the left side
is zero because both Pn-1 and Pn-2 interpolate the point (xi , .n). The rigbr side is also
zero. At x =x2 . .. .. x
11
_
1
, both sides are zero because all three polynomials. Pn-1 P
11
-z,
.Qn-2. imerpolate the points. For x =X
11
, both sides are identical because P
11
-t(X
11
) =
Qn-2(.\'n). 0
We denote Lbe degree 11 - J coefficient of Lbe unique degree .::: 11 - 1 polynomial interpo-
lating XJ Xrr by f[xt .. . Xn 1.
Using this definition, the degree n - 1 coefficient of the left-hand side in Lemma 3.4 is
flxl . .. Xn] (Xn - XJ).
and the degree n - 1 coefficient of the right-hand side is
Since they must be equal, we have proved the following:
If f[.,l ... Xn] denotes the degree n - 1 coefficient of Lbe degree .::: n - 1 polynomial
i oterpolali.ng x , , ... , x,, then
. , ) _ j[x2 ... x,J - .f[.\'1 .. . x,_l]
Jlx1 ... ,t" - .
x,l - XJ
(3.8)

Now we know how to find lhe degree 11 - i coefficiem. Using the recursive nature of (3.8),
we can C\aluate it by using a Newton divided difference triangle.
We tberefore specialize our discussion to the Newton form:
P
11
-t(X) =OJ+ 112(X- :q ) + OJ(X- .q)(X- X:?)
+ ... + an(X - Xl) .. (x- Xn-J). (3.9)
Firsl. is it always possible to write the interpolating polynomial in this form? We show that
it is possible, by soJ,ing for the coefficients a; in terms of the data poults )';. For example.
substituting .\'[ into the Newton fom1 (3.9) yields
(3. iO)
THEOREM 3.7
3.2 Interpolation Error I 157
Substiruting x2 yields
(3. 1, l)
so we may ulsu,- solve for "2 because a, is known fFom (3. 10) and the coefticicnt of a2 is
nonzero. Substituting x3, we see the same thing:
(3. 12)
In general,
Of +a'!(Xm - .q) +a3(Xm -.q)(Xm -x2) + .. +am(Xm -xl) .. (Xm
=P,,_,(x
111
)=_\1
111
(3. 13)
The importam facts, are that the previous (l; are known and tbaL the coefficient of a
111
in the
equation is n()nzero because the points :c; are distincr.
Now that know l):te Newton form always exisLS. we show how to compute the tlrn. Of
course, we already know the degree 11 - J coefficient from Lemma 3.6, an = flx 1 .. Xn 1.
For a polynomial wrinen in Newton form, denote by the m - l poly-
nomial composed of lbe first m tem1s of the Newton fom1 of Pn-l Note that P
11
- 1 )
11
:- 1
interpolates (x 1 , ,Vi), .. , Ym) because Pn-1 does and because the higher terms are all
zero at those points. By uniqueness of ring polynomial, ( P
11
-l )m-1 is the degree
5 m - 1 interpol::tting polynmn,i,n.l of.TJ .... , Xm, and so by Lemma 3.6. am = f[:q . .. x
111
] .
We have proved the following theorem:
Given.n y ,), ... , (xll. y
11
.) such that the :q arc distinct, lbe polynomial. P
11
-l (x)
written irr Newton form (3(9) has coefficients given by
for 1 5 m n. I11 other the NewlQil divided difference formula gives the unique
n - 1 interpolating polynomial through then poinls.
Nex.t we prove the Tmcrpolalion .Error Theorem 3.3. Consider adding one more poi111
x to the set of interpolation poinrs. The new inrerpo!atio11 polynl1mial would be
Evaluated allhe extra poinu, P" (x) = f(.x), so
f(x) = P11 - 1(x) + f[x, ... xnx](x- x!)(x- x
11
). (3.14)
This fonnulct.is tn1e [or all x. Now dell.Jle
h(t) = J(t)- Pn- 1 (t )- f[.\' ! .. xr) .. (t - Xn).
Note tbm h.(x) = 0 by (3.14) and 0 = lt (xt) = .. =

because Pn- 1 interpol ares fat
these poluts. Bet ween each neigbbori ng pair of then + I potnts x, x 1, ... , x
11
, there must be
158 I CHAPTER 3 Interpolation
a new poim where h' = 0. by Rolle's Theorem (see Chapter 0). I11ere are 11 of the e points.
Between each pair of these, there must be a new point where lz" = 0: there are n - I of
t.bese. Comjnuing in this way, there must be one point c for which h(" >(c) = 0, where c lies
between the small est and largest of x. XJ , x,. NOle that
because the 11th derivative of the polynomial Pn-1 (t) is zero. Substituting c gives
whicb leads to
j (n) (c)
f(x) = Pn - l (x) + (x- XJ) (.t - x,. ) ,
n!
using (3. t4).
3.2.3 Runge phenomenon
Polynomials can fit any set of data points. as Theorem 3.2 shows. However, there are some
shapes that polynomials prefer over others. You can achleve a better understancling of this
point by playing with Program 3.2. Try data p o i n ~ that cause Lhe function to be zero at
equally spaced points x = -3, -2.5, - 2. - 1.5 ..... 2.5, 3, except for x = 0, where we set
a value. of 1. Tbe data poi nts arc flat along the x-axis, except for a triangular "bump'' at
x = 0, as shown in Figure 3.5.
The polynomial that goes through points siruated like this refuses to stay between 0
and 1. unlike Lbe data points. This is an illusu-:uion of the so-called Runge phenomenon.
ft is usually used to describe extreme polynomial wiggle'' associated with high-degree
polynomial interpolation at evenly-spaced points.
y
Figure 3.5 Interpolati on of
triangular bump function. The
interpoi<Jting polynomial wiggles
much more than the Input dena
points.
EXAMPLE 3.9
3.2 Exercises
3.2 Interpolation Error I 159
Interpolate f (x) = 1/(1 + 12x
2
) ar evenly-spaced points in (-1. 1].
This is called the Runge e..xample.. The function h:ts the same general shape as the
triangular bump in Figure 3.5. Figure 3.6 shows the result of the interpolation, behavior
!.bat is characteristic of the Runge phenomenon: polynomial wiggle near the ends of the
interpolation interval.
y y
- X - X
(a) (b)
Figure 3.6 Runge example. Polynomial interpolation of the Runge function of
Example 3.9 at evenly spaced base points causes extreme variation near the ends
of the interval, similar to Figure 3.5. (a) 15 base points (bl 25 base points.
As we have seen, examples with the Runge phenomenon characteristically h ~ v e large
error near the outside of the interval of data points. The cure for this problem is intuitive:
Move some of the interpolation points toward the outside of the interval. where the function
producing the data can be bener fiL We will see how to accomplish this in the next section
on Chebyshev interpolation.
1. (a) Find the degree 2 interpol ating polynomial Pz(x) through the points {0, 0), (rr/2.1). and
(rr, 0). (b) Calculate P2Crr / 4), an approximation for sin(rr / 4). (c) Use Theorem 3.3 ro give an
error bound for the approximation in part (b). (d) Using a calculator or M">TI.A.B, compare the
actual error to your error bound.
2. (a) Given the data points ( I. 0), (2, In 2), (4, ln4). find the degree 2 interpolating polynomial.
(b) Use the result of (a) to approximate In 3. (c) Use Theorem 3.3 to give an error bound for the
approximation in part (b). (d) Compare the actual error to your error bound.
3. Assume that the polynomial P9(x) interpolates the function f(x) = e-2:c ar the 10
evenly-spaced points x= 0, 1/9, 2/ 9.3/9 .... , S/9. 1. (a) Find an upper bound for the error
1/(l/2)- 1'9(1/ 2)1. (b) How many decimal places can you guarantee to be correct if ?9( 1/2)
is used to approximate e-
1
?
4. Consider the interpolating polynomial for f(x) = 1/(x + 5) with interpolation nodes
x = 0, 2, 4, 6, 8. 10. Fmd an upper bound for the interpolation error at (a) x = I and (b) x = 5.
160 I CHAPTER 3 Interpolation
5. t\ s umc that a function f(x) bas been approxjmated by the degree 5 interpolating polynomial
P (x) , using the data points (x, . f(x,)). where .q = .I. x2 = .l. XJ = .3. x.t = .4, xs = .5, _
X6 = .6. Do you expect the in!erpolation error lf(x) - P(x)l to be smaJler for x = .35 orfor
x = .55? Quantify your answer.
6. Assume that rhe polynomial P5(x) u function f(x) at the <:ix data points (x
1
,
/(x;)) with x-coordinat.eS Xt = O.xz = .2.x3 = A.x4 = .6.x.s = .S. and X6 = 1. As ume that
the interpolation error al x = .3 is 1/(.3) - Ps(.3)1 == .01. Estimate the new interpolation error
1/(.3) - P7(.3)J that would result if rwo additional interpolation points (x6 . y
6
) == (. 1 ,J(.l ))
and (x7. = (.5, f (.5)) are added. \Vhac assumptions have you made LO produce thi s
estimate'!
3.2 Computer Problems
1. (a) Use the method of divided differences 10 find the degree 4 interpohtcing polynomial P
4
(x)
for the data (0.6. 1.433329). (0.7. 1.632316), (0.8. 1.896481 ). (0.9. 2.247908). and
(1.0. 2. 71 8282). (b) Calculate P.: {0.82) and P.: (0.98). (c) The preceding data come from the
function f(x) = eA
1
. Use the interpolation error formula to find upper bounds for the error at
x = 0.82 and x = 0.98, and compare the bound with tfie actual error. (d) Plot the actual
'
interpolation error P(x) - eon the intervals f.5.1) and [0. 2).
2. Plot t..he interpolation error of !.he s inl key from Program 3.3 on the interval[-21T. 21T ].
3. T.he total wodd C:li l production in mil lions of barrels per d:ly.is show11 in the table that foUows.
Determine and plot !.he degree 9 polynomial through the data. Usc it ro estiD1ate 1010 oil
production. Does the Runge phenomenon occur in this example? Io your opinion. is rhe
interpolating polynomial a good model of the data? Explain.
year bbVday ( x 10
6
)
1994 67.052
1995 68.008
1996 69.803
1997 72.024
1998
.
73.400
1999 72.063
2000 74.669
200l 74.487
2002 74.065
2003 76.777
4. Use the degree three polynomial Through the first four data points in Computer Problem 3 to
estimate the J 998 world oil production. 1s the Runge phenomenon present?
13.3 I CHEBYSHEV INTERPOLATION
It is common to choose the base points x; for interpolation to be evenly spaced. Ln many
cases, the data to be interpolated are available only in that form- for example, when the

You might also like