You are on page 1of 30

NUMERICAL ANALYSIS

Asst. Prof. S. Ebru DAS


POLYNOMIAL INTERPOLATION

For the estimation of the intermediate values between spesific data points,

the most common method used for this purpose is Polynomial Interpolation.

The general formula for an (n-1)th order polynomial can be written as

𝑓 𝑥 = 𝑎1 + 𝑎2 𝑥 + ⋯ + 𝑎𝑛 𝑥 𝑛−1 (1)
For n data points, there is one and only one polynomial of order (n-1) that
passes through all the points.
POLYNOMIAL INTERPOLATION

For example, there is only one straight line (first-order polynomial) that connects two
points .

Similarly, only one parabola connects a set of three points.


POLYNOMIAL INTERPOLATION

Polynomial interpolation consists of determining the unique (n-1)th order polynomial


that fits n data points. This polynomial then provides a formula to compute
intermediate values.

Before proceeding, we should note that MATLAB represents polynomial coefficients in


a different manner than Eq. (1). Rather than using increasing powers of x, it uses
decreasing powers as in

𝑓 𝑥 = 𝑝1 𝑥 𝑛−1 + 𝑝2 𝑥 𝑛−2 + ⋯ + 𝑝𝑛 (2)


DETERMINING POLYNOMIAL COEFFICIENTS

A direct way for computing the coefficients of Eq. (2) is based on the fact that n data
points are required to determine the n coefficients. As in the following example, this
allows us to generate n linear algebraic equations that we can solve together for the

coefficients.
DETERMINING POLYNOMIAL COEFFICIENTS

Example 1. Determining Polynomial Coefficients with Simultaneous Equations


Suppose that we want to determine the coefficients of the parabola,
𝑓 𝑥 = 𝑝1 𝑥 2 + 𝑝2 𝑥 + 𝑝3 , that passes through the three values
𝑥1 = 300 , 𝑓(𝑥1 ) = 0.616
𝑥2 = 400 , 𝑓(𝑥2 ) = 0.525
𝑥3 = 500 , 𝑓(𝑥3 ) = 0.457

Each of these pairs can be substituted into parabola to produce a system of three equations:
DETERMINING POLYNOMIAL COEFFICIENTS

0.616 = 𝑝1 (300)2 +𝑝2 300 + 𝑝3


0.525 = 𝑝1 (400)2 +𝑝2 400 + 𝑝3
0.457 = 𝑝1 (500)2 +𝑝2 500 + 𝑝3
or in the matrix form
90,000 300 1 𝑝1 0.616
160,000 400 1 𝑝2 = 0.525
250,000 500 1 𝑝3 0.457

𝑓 𝑥 = 0.00000115𝑥 2 −0.001715𝑥 + 1.027


NEWTON INTERPOLATING POLYNOMIAL

There are many alternative forms for expressing an interpolating polynomial beyond
the familiar format of Eq. (2). Newton’s interpolating polynomial is among the most
popular and useful forms.

Let us introduce the first and second order versions because of their simple visual
interpretation.
LINEAR INTERPOLATION

The simplest form of interpolation is to connect two data points with a straight line. This technique
, called linear interpolation, is showed graphically
LINEAR INTERPOLATION
Using similar triangles,
𝑓1 𝑥 − 𝑓(𝑥1 ) 𝑓(𝑥2 ) − 𝑓(𝑥1 )
=
𝑥 − 𝑥1 𝑥2 − 𝑥1

which can be rearranged to find


𝑓(𝑥2 ) − 𝑓(𝑥1 )
𝑓1 𝑥 = 𝑓 𝑥1 + (𝑥 − 𝑥1 )
𝑥2 − 𝑥1

which is the Newton linear-interpolation formula. The notation 𝑓1 𝑥 designates that this is a first-
order interpolating polynomial
LINEAR INTERPOLATION
Example 1.

Estimate the natural logarithm of 2 using linear interpolation.

First, perform the computation by interpolating between ln 1 = 0 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.


LINEAR INTERPOLATION
Example 1.
If we use linear interpolation from 𝑥1 = 1 to 𝑥2 = 6 to give

1.791759 − 0
𝑓1 2 = 0 + 2 − 1 = 0.3583519
6−1
which represents an error of 𝜀𝑡 = 48.3%
If we use linear interpolation from 𝑥1 = 1 to 𝑥2 = 4 to give

1.386294 − 0
𝑓1 2 = 0 + 2 − 1 = 0.4620981
4−1

which represents an error of 𝜀𝑡 = 33.3%


LINEAR INTERPOLATION
QUADRATIC INTERPOLATION

The error in the previous example resulted from approximating a curve with a straight line.
For improving the estimate, we can introduce some curvature into the line connecting the
points.

If we have three data points, this can be accomplished with a second-order polynomial
(also called a quadratic polynomial or a parabola). A suitable form for this purpose is

𝑓2 𝑥 = 𝑏1 + 𝑏2 𝑥 − 𝑥1 + 𝑏3 𝑥 − 𝑥1 𝑥 − 𝑥2 (3)
QUADRATIC INTERPOLATION
A simple procedure can be used to determine the values of the coefficients.

For 𝑏1 , Eq. (3) with 𝑥 = 𝑥1 can be used to compute

𝑏1 = 𝑓 𝑥1 (4)

Equation (4) can be substituted into Eq. (3), which can be evaluated at 𝑥 = 𝑥2 for

𝑓(𝑥2 ) − 𝑓(𝑥1 )
𝑏2 = (5)
𝑥2 − 𝑥1
Finally, Eqs. (4) and (5) can be substituted into Eq. (3), which can be evaluated at 𝑥 = 𝑥3 and solved
for
𝑓(𝑥3 ) − 𝑓(𝑥2 ) 𝑓(𝑥2 ) − 𝑓(𝑥1 )

𝑥3 − 𝑥2 𝑥2 − 𝑥1
𝑏3 = (6)
𝑥3 − 𝑥1
QUADRATIC INTERPOLATION
Example 2. Employ a second-order Newton polynomial to estimate ln 2 with the same three points
used in Example 1.
𝑥1 = 1 , 𝑓(𝑥1 ) = 0
𝑥2 = 4 , 𝑓(𝑥2 ) = 1.386294
𝑥3 = 6 , 𝑓(𝑥3 ) = 1.791759

If we use eq. (4)-(5) and (6), we find


𝑏1 = 𝑓 𝑥1 = 0
𝑓(𝑥2 ) − 𝑓(𝑥1 ) 1.386294 − 0
𝑏2 = = = 0.4620981
𝑥2 − 𝑥1 4−1
𝑓(𝑥3 ) − 𝑓(𝑥2 ) 𝑓(𝑥2 ) − 𝑓(𝑥1 ) 1.791759 − 1.386294 1.386294 − 0
− −
𝑥3 − 𝑥2 𝑥2 − 𝑥1 6 − 4 4−1
𝑏3 = = = −0.0518731
𝑥3 − 𝑥1 6−1
QUADRATIC INTERPOLATION
GENERAL FORM OF NEWTON’S INTERPOLATING
POLYNOMIALS
The preceding analysis can be generalized to fit an (n − 1)th-order polynomial to n data points. The
(n − 1)th-order polynomial is

𝑓𝑛−1 𝑥 = 𝑏1 + 𝑏2 𝑥 − 𝑥1 + ⋯ + 𝑏𝑛 𝑥 − 𝑥1 𝑥 − 𝑥2 𝑥 − 𝑥𝑛−1 (7)

As was done previously with linear and quadratic interpolation, data points can be used to
evaluate the coefficients 𝑏1 , 𝑏2 , . . . , 𝑏𝑛 . For an (n − 1)th-order polynomial, n data points
are required:
[𝑥1 , f (𝑥1 )], [𝑥2 , f (𝑥2 )], . . . , [𝑥𝑛 , f (𝑥𝑛 )].
We use these data points and the following equations to evaluate the coefficients:
GENERAL FORM OF NEWTON’S INTERPOLATING
POLYNOMIALS
𝑏1 = 𝑓 𝑥1
𝑏2 = 𝑓[𝑥2 , 𝑥1 ]
𝑏3 = 𝑓[𝑥3 ,𝑥2 , 𝑥1 ]
.................
𝑏𝑛 = 𝑓[𝑥𝑛 ,𝑥𝑛−1 , … , 𝑥1 ]

where the bracketed function evaluations are finite divided differences.


For example, the first finite divided difference is represented generally as
𝑓(𝑥𝑖 ) − 𝑓(𝑥𝑗 )
𝑓 𝑥𝑖 , 𝑥𝑗 =
𝑥𝑖 − 𝑥𝑗
GENERAL FORM OF NEWTON’S INTERPOLATING
POLYNOMIALS
The second finite divided difference, which represents the difference of two first divided differences, is
expressed generally as
𝑓 𝑥𝑖 , 𝑥𝑗 − 𝑓 𝑥𝑗 , 𝑥𝑘
𝑓 𝑥𝑖 , 𝑥𝑗 , 𝑥𝑘 =
𝑥𝑖 − 𝑥𝑘
Similarly, the nth finite divided difference is
𝑓 𝑥𝑛 , 𝑥𝑛−1 , … , 𝑥2 − 𝑓 𝑥𝑛−1 , 𝑥𝑛−2 , … , 𝑥1
𝑓 𝑥𝑛 , 𝑥𝑛−1 , … , 𝑥1 =
𝑥𝑛 − 𝑥1

These differences can be used to evaluate the coefficients. The general form of Newton’s
interpolating polynomial :
𝑓𝑛−1 𝑥 = 𝑓 𝑥1 + 𝑥 − 𝑥1 𝑓[𝑥2 , 𝑥1 ] + ⋯ + 𝑓[𝑥𝑛 ,𝑥𝑛−1 , … , 𝑥1 ] 𝑥 − 𝑥1 𝑥 − 𝑥2 𝑥 − 𝑥𝑛−1
QUADRATIC INTERPOLATION
Example 3. Let us take example 2 adding 𝑥4 for estimating a third order Newton interpolating
polynomial.
𝑥1 = 1 , 𝑓(𝑥1 ) = 0
𝑥2 = 4 , 𝑓(𝑥2 ) = 1.386294
𝑥3 = 6 , 𝑓(𝑥3 ) = 1.791759
𝑥4 = 5 , 𝑓(𝑥4 ) = 1.609438

𝑓3 𝑥 = 𝑓 𝑥1 + 𝑥 − 𝑥1 𝑓 𝑥2 , 𝑥1 + 𝑥 − 𝑥1 𝑥 − 𝑥2 𝑓 𝑥3 ,𝑥2 , 𝑥1 + 𝑥 − 𝑥1 𝑥 − 𝑥2 𝑥 − 𝑥3 𝑓 𝑥4 ,𝑥3 ,𝑥2 , 𝑥1


QUADRATIC INTERPOLATION
𝑓(𝑥2 ) − 𝑓(𝑥1 ) 1.386294 − 0
𝑓 𝑥2 , 𝑥1 = = = 0.4620981
𝑥2 − 𝑥1 4−1
𝑓(𝑥3 ) − 𝑓(𝑥2 ) 1.791759 − 1.386294
𝑓 𝑥3 , 𝑥2 = = = 0.2027326
𝑥3 − 𝑥2 6−4
𝑓(𝑥4 ) − 𝑓(𝑥3 ) 1.609438 − 1.791759
𝑓 𝑥4 , 𝑥3 = = = 0.1823216
𝑥4 − 𝑥3 5−6
𝑓 𝑥3 , 𝑥2 − 𝑓 𝑥2 , 𝑥1 0.2027326 − 0.4620981
𝑓 𝑥3 ,𝑥2 , 𝑥1 = = = −0.05187311
𝑥3 − 𝑥1 6−1
𝑓 𝑥4 , 𝑥3 − 𝑓 𝑥3 , 𝑥2 0.1823216 − 0.2027326
𝑓 𝑥4 , 𝑥3 ,𝑥2 = = = −0.02041100
𝑥4 − 𝑥2 5−4
𝑓 𝑥4 , 𝑥3 , 𝑥2 − 𝑓 𝑥3 , 𝑥2 , 𝑥1 −0.02041100 − ( − 0.05187311)
𝑓 𝑥4 , 𝑥3 ,𝑥2 , 𝑥1 = = = 0.007865529
𝑥4 − 𝑥1 5−1
QUADRATIC INTERPOLATION

If we write these results in the polynomial, we find that


𝑓3 2 = 0.6287686
LAGRANGE INTERPOLATING POLYNOMIAL
Suppose we formulate a linear interpolating polynomial as the weighted average of the
two values that we are connecting by a straight line:
𝑓 𝑥 = 𝐿1 𝑓 𝑥1 + 𝐿2 𝑓 𝑥2
where the L’s are the weighting coefficients. It is logical that the first weighting coefficient
is the straight line that is equal to 1 at 𝑥1 and 0 at 𝑥2 :
𝑥 − 𝑥2
𝐿1 =
𝑥1 − 𝑥2
Similarly, the second coefficient is the straight line that is equal to 1 at 𝑥2 and 0 at 𝑥1 .
𝑥 − 𝑥1
𝐿2 =
𝑥2 − 𝑥1
LAGRANGE INTERPOLATING POLYNOMIAL

If we write these coefficients in the line, we find

𝑥−𝑥2 𝑥−𝑥1
𝑓1 𝑥 =
𝑥1 −𝑥2
𝑓 𝑥1 +
𝑥2 −𝑥1
𝑓 𝑥2 (1)

where 𝑓1 𝑥 is a first-order polynomial. Equation (1) is referred to as the linear Lagrange


interpolating polynomial.
LAGRANGE INTERPOLATING POLYNOMIAL

We can use the same strategy to fit a parabola through three points. For this case, three
parabolas would be used with each one passing through one of the points and equaling
zero at the other two. Then, their sum would represent the unique parabola that
connects the three points. Such a second-order Lagrange interpolating polynomial can be
written as

(𝑥−𝑥2 )(𝑥−𝑥3 ) (𝑥−𝑥1 )(𝑥−𝑥3 ) (𝑥−𝑥1 )(𝑥−𝑥2 )


𝑓2 𝑥 = 𝑓 𝑥1 + 𝑓 𝑥2 + 𝑓 𝑥3 (2)
(𝑥1 −𝑥2 )(𝑥1 −𝑥3 ) (𝑥2 −𝑥1 )(𝑥2 −𝑥3 ) (𝑥3 −𝑥1 )(𝑥3 −𝑥2 )
LAGRANGE INTERPOLATING POLYNOMIAL

With the light of first- and second-order versions, we can write a general formula for
higher-order Lagrange polynomials as
𝑛
𝑓𝑛−1 𝑥 = 𝑖=1 𝐿𝑖 (𝑥) 𝑓 𝑥𝑖 (3)

where
𝑛
𝑥 − 𝑥𝑗
𝐿𝑖 (𝑥) =
𝑥𝑖 − 𝑥𝑗
𝑗=1
𝑗≠𝑖

and n is the number of data points.


LAGRANGE INTERPOLATING POLYNOMIAL

Example 1. Use a Lagrange interpolating polynomial of the first and second order to
evaluate the density of unused motor oil at T = 15 °C based on the following data:
𝑥1 = 0 , 𝑓 𝑥1 = 3.85

𝑥2 = 20 , 𝑓 𝑥1 = 0.8

𝑥3 = 40 , 𝑓 𝑥1 = 0.212
LAGRANGE INTERPOLATING POLYNOMIAL

First order Lagrange interpolating polynomial is

𝑥 − 𝑥2 𝑥 − 𝑥1
𝑓1 𝑥 = 𝑓 𝑥1 + 𝑓 𝑥2
𝑥1 − 𝑥2 𝑥2 − 𝑥1
In our example 𝑥 = 15, so we can select the two points as 𝑥1 = 0 and 𝑥2 = 20

15 − 20 15 − 0
𝑓1 15 = 3.85 + 0.8 = 0.9625 + 0.6 = 1.5625
0 − 20 20 − 0
LAGRANGE INTERPOLATING POLYNOMIAL

Second order Lagrange interpolating polynomial is

(𝑥 − 𝑥2 )(𝑥 − 𝑥3 ) (𝑥 − 𝑥1 )(𝑥 − 𝑥3 ) (𝑥 − 𝑥1 )(𝑥 − 𝑥2 )


𝑓2 𝑥 = 𝑓 𝑥1 + 𝑓 𝑥2 + 𝑓 𝑥3
(𝑥1 − 𝑥2 )(𝑥1 − 𝑥3 ) (𝑥2 − 𝑥1 )(𝑥2 − 𝑥3 ) (𝑥3 − 𝑥1 )(𝑥3 − 𝑥2 )

In our example 𝑥 = 15, so we can select the three points as 𝑥1 = 0, 𝑥2 = 20 , 𝑥3 = 40


(15 − 20)(15 − 40) (15 − 0)(15 − 40) (15 − 0)(15 − 20)
𝑓2 𝑥 = 3.85 + 0.8 + 0.212
(0 − 20)(0 − 40) (20 − 0)(20 − 40) (40 − 0)(40 − 20)

(15 − 20)(15 − 40) (15 − 0)(15 − 40) (15 − 0)(15 − 20)


𝑓2 𝑥 = 3.85 + 0.8 + 0.212
(0 − 20)(0 − 40) (20 − 0)(20 − 40) (40 − 0)(40 − 20)

𝑓2 𝑥 = 0.6015625 + 0.75 − 0.019875 = 1.3316875

You might also like