Professional Documents
Culture Documents
Contents
3.1 Lagrange Approximation . . . . . . . . . . . . . . . . . . . . . 57
3.1.1 Pseudocode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
3.1.2 Additional notes about Lagrange polynomials . . . . . . . . . . 59
3.2 Newton Polynomials, Newton Interpolation Polynomial . . 60
3.2.1 Newton’s Polynomials . . . . . . . . . . . . . . . . . . . . . . . 60
3.2.2 Notes about Newton’s polynomials . . . . . . . . . . . . . . . . 65
3.2.3 Newton’s Interpolating Polynomial . . . . . . . . . . . . . . . . 65
54
Figure 3.1: Various order polynomials
exactly through all of the points. The polynomial,however, can be written in different
mathematical forms. This chapter shows how to derive three forms of polynomials
(standard, Lagrange, and Newton’s). The different forms are suitable for use in different
circumstances.
The standard form of an mth -order polynomial is:
a4 14 + a3 13 + a2 12 + a1 1 + a0 = 2
a4 44 + a3 43 + a2 42 + a1 4 + a0 = 6
a4 74 + a3 73 + a2 72 + a1 7 + a0 = 4
a4 104 + a3 103 + a2 102 + a1 10 + a0 = 8
a4 134 + a3 133 + a2 132 + a1 13 + a0 = 10
The solution of this system of equations gives the values of the coefficients. In practise,
solving the systems of equations, especially for higher-order polynomials is not efficient.
55
(a) (b)
Figure 3.2: (a) The approximating polynomial P (x) can be used for interpolation
at the point (4, P (4)) and extrapolation at the point (5.5, P(5.5)). (b) The
approximating polynomial P (x) is differentiated and P (x) is used to find the
slope at the interpolation point (4, P (4)).
It is also possible to write the polynomial in other forms that may be easier to use like
the Lagrange and Newton forms.
Situations in statistical and scientific analysis arise where the function y = f (x) is
available only at N + 1 tabulated points (xk , yk ), and a method is needed to approximate
f(x) at non-tabulated abscissas. If there is a significant amount of error in the tabulated
values, then the methods of curve fitting in Chapter 5 should be considered. On the other
hand, if the points (xk , yk ) are known to a high degree of accuracy, then the polynomial
curve y = P (x) that passes through them can be considered. When x0 < x < xN , the
approximation P (x) is called an interpolated value. If either x < x0 or xN < x, then
P (x) is called an extrapolated value. Polynomials are used to design software algorithms
to approximate functions, for numerical differentiation, for numerical integration, and for
making computer-drawn curves that must pass through specified points. Let us briefly
mention how to evaluate the polynomial P (x):
and the indefinite integral I(x) = P (x)dx, which satisfies I 0 (x) = P (x), is
R
aN xN +1 aN −1 xN a2 x3 a1 x2
I(x) = + + ··· + + + a0 x + C (3.4)
N +1 N 3 2
where C is the constant of integration.
56
3.1. Lagrange Approximation
f (x) = y = a1 (x − x2 ) + a2 (x − x1 ) (3.5)
(x − x2 ) (x − x1 )
f (x) = y1 + y2 (3.8)
(x1 − x2 ) (x2 − x1 )
Eq. (3.8) is a linear function of x (an equation of a straight line that connects the
two points). It is easy to see that if x = x1 is substituted in Eq. (3.8), the value of
the polynomial is y1 , and if x = x2 is substituted, the value of the polynomial is y2 .
Substituting a value of x between the points gives an interpolated value of y. Eq. (3.8)
can also be rewritten in the standard form f (x) = a1 x + a0 :
(y2 − y1 ) x2 y 1 − x1 y 2
f (x) = x+ (3.9)
(x2 − x1 ) (x2 − x1 )
For three points, (x1 , y1 ), (x2 , y2 ), and (x3 , y3 ), the second-order Lagrange polynomial
that passes through the points (Fig. 3.3(b)) has the form:
Once the coefficients are determined such that the polynomial passes through the three
points, the polynomial is:
(x − x2 ) (x − x3 ) (x − x1 ) (x − x3 ) (x − x1 ) (x − x2 )
f (x) = y1 + y2 + y3 (3.11)
(x1 − x2 ) (x1 − x3 ) (x2 − x1 ) (x2 − x3 ) (x3 − x1 ) (x3 − x2 )
57
3.1. Lagrange Approximation
(a) (b)
Following the format of the polynomials in Eq. (3.8) and (3.11), the general
formula of an (n − 1) order Lagrange polynomial that passes through n points
(x1 , y1 ), (x2 , y2 ), . . . , (xn , yn ) is:
(x − x2 ) (x − x3 ) . . . (x − xn ) (x − x1 ) (x − x3 ) . . . (x − xn )
f (x) = y1 + y2 + ....
(x1 − x2 ) (x1 − x3 ) . . . (x1 − xn ) (x2 − x1 ) (x2 − x3 ) . . . (x2 − xn )
(x − x1 ) (x − x2 ) . . . (x − xi−1 ) (x − xi+1 ) . . . (x − xn )
+ yi + ...
(xi − x1 ) (xi − x2 ) . . . (xi − xi−1 ) (xi − xi+1 ) . . . (xi − xn )
(x − x1 ) (x − x2 ) . . . (x − xn−1 )
+ yn
(xn − x1 ) (xn − x2 ) . . . (xn − xn−1 )
(3.12)
On the right-hand side of Eq. (3.12) the numerator of the ith term does not contain
(x − xi ), and the denominator does not contain (xi − xi ). Consequently, when the
coordinate xi of one of the n points is substituted in Eq. (3.12), the value of the polynomial
is equal to Yi . Eq. (3.12) can be written in a compact form using summation and product
notation as:
n n n
(x − xj )
f (x) = yi Li (x) = (3.13)
X X Y
yi
i=1 i=1 j=1 (xi − xj )
j6=i
(x − xj )
where Li (x) = are called the Lagrange functions. This form can easily
Qn
j=1
(xi − xj )
j6=i
58
3.1. Lagrange Approximation
3.1.1 Pseudocode
1. Start
2. Read xi and yi for i= 1 to n
% n is the number of data
3. Read xp
% yp is the corresponding value of xp which is to be determined.
4. Initialize: yp = 0
5. For i = 1 to n
p = 1
For j =1 to n
If i not equals to j
p = p * (xp - Xj)/(Xi - Xj)
End If
Next j
yp = yp + p * Yi
Next i
6. Print yp
7. Stop
• For a given set of points, the whole expression of the interpolation polynomial has
to be calculated for every value of x. In other words,the interpolation calculations
for each value of x are independent of others. This is different from other forms
where once the coefficients of the polynomial are determined, they can be used for
calculating different values of x.
• If an interpolated value is calculated for a given set of data points, and then the data
set is enlarged to include additional points, all the terms of the Lagrange polynomial
have to be calculated again. This is different from Newton’s polynomials where only
the new terms have to be calculated if more data points are added.
59
3.2. Newton Polynomials, Newton Interpolation Polynomial
Example 1
2. Use the polynomial obtained in part (a) to determine the interpolated value
for x = 3.
Solution
(a) Following the form of Eq.(3.12), the Lagrange polynomial for the five given points is:
60
3.2. Newton Polynomials, Newton Interpolation Polynomial
n points is:
The special feature of this form of the polynomial is that the coefficients a1 through
an can be determined using a simple mathematical procedure. (Determination of the
coefficients does not require a solution of a system of n equations.) Once the coefficients
are known, the polynomial can be used for calculating an interpolated value at any x.
Newton’s interpolating polynomials have additional desirable features that make them a
popular choice. The data points do not have to be in descending or ascending order, or
in any order. Moreover, after the n coefficients of an n − 1 order Newton’s interpolating
polynomial are determined for n given points, more points can be added to the data set
and only the new additional coefficients have to be determined.
y2 − y1
f (x) = y1 + (x − x1 ) (3.17)
x2 − x1
Comparing Eq. (3.16) with Eq. (3.14) gives the values of the coefficients a1 and a2 in
terms of the coordinates of the points:
61
3.2. Newton Polynomials, Newton Interpolation Polynomial
y2 − y1
a1 = y1 and a2 =
x2 − x 1
Notice that the coefficients a2 is the slope of the line that connects the two points. Or
in other words it can be said that a2 is the two-point forward difference approximation
for the first derivative at (x1 , y1 ).
points. The coefficients a1 , a2 anda3 can be determined by substituting the three points
in Eq.(3.17). Substituting x = x1 and f (x1 ) = y1 gives a1 = y1 . Substituting the second
point, x = x2 and f (x2 ) = y2 , (and a1 = y1 ) in Eq.(3.17) gives:
y2 − y1
y2 = y1 + a2 (x2 − x1 ) or a2 = (3.19)
x2 − x 1
y2 − y1
Substituting the third point, x = x3 and f (x3 ) = y3 (as well as a1 = y1 and a2 = )
x2 − x 1
in Eq.(3.17) gives:
y2 − y1
y3 = y1 + (x3 − x1 ) + a3 (x3 − x1 )(x3 − x2 ) (3.20)
x2 − x1
Eq. (3.19) can be solved for a3 and rearranged to give (after some algebraic calculations):
y3 − y2 y2 − y1
−
x − x2 x2 − x1
a3 = 3 (3.21)
(x3 − x1 )
62
3.2. Newton Polynomials, Newton Interpolation Polynomial
The coefficients a1 and a2 are the same in the first-order and second-order polynomials.
This means that if two points are given and a first-order Newton’s polynomial is fit to pass
through those points, and then a third point is added, the polynomial can be changed to
be of second-order and pass through the three points by only determining the value of
one additional coefficient.
The formulas for the coefficients a1 , a2 anda3 are the same as for the second order
polynomial. The formula for the coefficient a4 can be obtained by substituting (x4 , y4 )
in Eq.(3.21) and solving for a4 , which gives:
y4 − y3 y3 − y2 y3 − y2 y2 − y1
− −
x4 − x3 x3 − x2 x3 − x2 x2 − x1
−
(x4 − x2 ) (x3 − x1 )
a4 = (3.23)
(x4 − x1 )
63
3.2. Newton Polynomials, Newton Interpolation Polynomial
f [x4 , x3 , x2 ] − f [x3 , x2 , x1 ]
f [x4 , x3 , x2 , x1 ] =
x4 − x1
f [x4 , x3 ] − f [x3 , x2 ] f [x3 , x2 ] − f [x2 , x1 ]
−
x 4 − x2 x3 − x1
=
(x4 − x1 )
y4 − y3 y3 − y2 y3 − y2 y2 − y1
− −
x4 − x3 x3 − x2 x − x2 x2 − x1
− 3
x4 − x2 x3 − x1
= = a4
(x4 − x1 )
The third divided difference is thus equal to the coefficient a4 . The next (fourth) divided
difference (when five data points are given) is :
f [x5 , x4 , x3 , x2 ] − f [x4 , x3 , x2 , x1 ]
f [x5 , x4 , x3 , x2 , x1 ] = = a5 (3.26)
x5 − x1
If more data points are given, the procedure for calculating higher differences continues
in the same manner. In general, when n data points are given, the procedure starts by
calculating (n − 1) first divided differences. Then (n − 2) second divided differences are
calculated from the first divided differences. This is followed by calculating (n − 3) third
divided differences from the second divided differences. This process ends when one nth
divided difference is calculated from two (n − 1) divided differences to give the coefficient
an . The procedure for finding the coefficients by using the divided differences can be
220 Chapter 6 Curve Fitting and Interpolation
followed in a divided difference table. One of the tables is given below for your reference.
a
1
I a
2
XI Yi I
� f[x2,xi]
a3
� I a4
/ / f[x3,x2,xi] �
X2 Y2
� I a5
f[x3,x2] � / f[x4,x3,x2,xi] � I
X3 Y3 / / f[X4,X3,X2] � / f[x5,X4,X3,X2,xi]
" f[x4,X3] � / f[x5,X4,X3,X2]
X4 Y4
< /"
f[X5,X4]
f[X5,X4,X3]
X5 Y5 /
Data Points First divided Second divided Third divided Fourth divided
difference difference difference difference
differences between two points (xi , yi ) and (xj , yj ) are given by:
yj − yi
f [xj , xi ] = (3.27)
With these xj −
definitions, xi ( -1)
the n order Newton's polynomial, Eq.
(6.46) is given by:
64
f(x)= y = y1+ f[x2, x1](x-x1)+ f[x3,x2,x1](x-x1)(x-x2)+ ... + f[xn,xn-l• ...,x2,x 1](x -x1)(x-x2)... (x-xn_1)
y (6.63)
3.2. Newton Polynomials, Newton Interpolation Polynomial
3.2.2 Notes about Newton’s polynomials
• The spacing between the data points do not have to be the same.
• For a given set of n points, once the coefficients a1 through an are determined, they
can be used for interpolation at any point between the data points.
Example 1
2. Use the polynomial obtained in part (a) to determine the interpolated value
for x=3.
Solution
1. (a) Newton’s polynomial for the given points has the form:
f (x) = y = a1 +a2 (x−1)+a3 (x−1)(x−2)+a4 (x−1)(x−2)(x−4)+a5 (x−1)(x−2)(x−4)(x−5)
(3.28)
The coefficients can be determined by the following divided difference table as given
below: With the coefficients determined, the polynomial is
f (x) =y
=52 − 47(x − 1) + 14(x − 1)(x − 2) − 6(x − 1)(x − 2)(x − 4)
+ 2(x − 1)(x − 2)(x − 4)(x − 5)
2. The interpolated value for x=3 is obtained by substituting for x in the polynomial:
f (3) =y
=52 − 47(3 − 1) + 14(3 − 1)(3 − 2) − 6(3 − 1)(3 − 2)(3 − 4)
+ 2(3 − 1)(3 − 2)(3 − 4)(3 − 5)
=6
65
3.2. Newton Polynomials, Newton Interpolation Polynomial
66