0% found this document useful (0 votes)
230 views26 pages

Lec. 3 Interpolation

The document discusses interpolation, which is approximating the values of a function between known data points. It covers linear interpolation, which uses straight lines, and quadratic interpolation, which introduces curvature. Newton's divided difference formula is presented as a general approach for polynomial interpolation of any degree. Examples are provided to illustrate linear and quadratic interpolation.

Uploaded by

Mahdi Hussein
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
230 views26 pages

Lec. 3 Interpolation

The document discusses interpolation, which is approximating the values of a function between known data points. It covers linear interpolation, which uses straight lines, and quadratic interpolation, which introduces curvature. Newton's divided difference formula is presented as a general approach for polynomial interpolation of any degree. Examples are provided to illustrate linear and quadratic interpolation.

Uploaded by

Mahdi Hussein
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 26

1 Chapter Three / Interpolation

3.1 Introduction
We are given the values of a function 𝒇(𝒙) at different points
𝒙𝟎 , 𝒙𝟏 , … . . 𝒙𝒏 , we want to find approximate values of the function 𝒇(𝒙) for
“new” x’s that lie between these points for which the function values are
given, and this process is called interpolation.
Continuing our discussion, we write these given values of a function (𝑓) in
the form
𝑓0 = 𝑓(𝑥0 ), 𝑓1 = 𝑓(𝑥1 ), … . . 𝑓𝑛 = 𝑓(𝑥𝑛 )
Or as ordered pairs
(𝑥0 , 𝑓0 ), (𝑥1 , 𝑓1 ), … . . (𝑥𝑛 , 𝑓𝑛 )
These function values come from a “mathematical” function, such as
a logarithm or a Bessel function. More frequently, they may be measured or
automatically recorded values of an “empirical” function, such as air
resistance of a car or an airplane at different speeds. Other examples of
functions that are “empirical” are the yield of a chemical process at different
temperatures or the size of the Iraq population as it appears from censuses
taken at 10-year intervals.

3.2 Types of interpolation


A- Linear Interpolation, the simplest form of interpolations to connect data
points with straight line.
B- Quadratic Interpolation, a strategy for improving the estimate is to
introduce some curvature into the line connecting the points. This can be
accomplished with a second order polynomial.

Lec. Hussein K. Jobair


2 Chapter Three / Interpolation

3.3 Newton's Divided-Difference Interpolating Polynomial

There are a variety of alternative forms for expressing an interpolating


polynomial. Newton’s divided-difference interpolating polynomial is
among the most popular and useful forms. Before presenting the general
equation, we will introduce the first and second-order versions because of
their simple visual interpretation.

3.3.1 Linear Interpolation


The simplest form of interpolation is to connect two data points with a
straight line. This technique, called linear interpolation, is depicted
graphically in Figure (3.1) using similar triangles

𝑦(𝑥1 )

𝑦1 (𝑥)

𝑦(𝑥0 )

𝑥0 𝑥 𝑥1 𝑥

Figure (3.1) Graphical depiction of linear interpolation

Lec. Hussein K. Jobair


3 Chapter Three / Interpolation

𝑦1 (𝑥) − 𝑦(𝑥0 ) 𝑦(𝑥1 ) − 𝑦(𝑥0 )


=
𝑥 − 𝑥0 𝑥1 − 𝑥0
Which can be rearranged to yield

𝑦(𝑥1 ) − 𝑦(𝑥0 )
𝑦1 (𝑥) = 𝑦(𝑥0 ) + (𝑥 − 𝑥0 )
𝑥1 − 𝑥0

Which is a linear-interpolation formula. The notation 𝑦1 (𝑥) designates


that this is a first-order interpolating polynomial.

Example (3.1)
Estimate the natural logarithm of 2 using linear interpolation. First, perform
the computation by interpolating between 𝑙𝑛 (1) = 0 and ln(6) =
1.791759. Then, repeat the procedure, but use a smaller interval from
𝑙𝑛 (1) to 𝑙𝑛 (4) = 1.386294. Note that the true value of 𝑙𝑛 (2) is
0.6931472.

Solution
We use a linear interpolation for 𝑙𝑛(2) from 𝑥0 = 1 to 𝑥1 = 6 to give

𝑦(𝑥1 ) − 𝑦(𝑥0 )
𝑦1 (𝑥) = 𝑦(𝑥0 ) + (𝑥 − 𝑥0 )
𝑥1 − 𝑥0
1.791759 − 0
𝑦1 (2) = 0 + (2 − 1) = 0.3583519
6−1
This means the percentage error is 48.3%. Using a smaller interval from
𝑥0 = 1 to 𝑥1 = 4
1.386294 − 0
𝑦1 (2) = 0 + (2 − 1) = 0.4620981
4−1

Lec. Hussein K. Jobair


4 Chapter Three / Interpolation

Thus, using the shorter interval reduces the percent relative error to 33.3%.
3.3.2 Quadratic Interpolation
The error in Example (3.1) resulted from our approximating a curve with a
straight line is large. Consequently, a strategy for improving the estimate is
to introduce some curvature into the line connecting the points. If three data
points are available, this can be accomplished with a second-order
polynomial (also called a quadratic polynomial or a parabola). A
particularly convenient form for this purpose is

𝑦2 (𝑥) = 𝑏0 + 𝑏1 (𝑥 − 𝑥0 ) + 𝑏2 (𝑥 − 𝑥0 )(𝑥 − 𝑥1 )

Or
𝑦2 (𝑥) = 𝑎0 + 𝑎1 𝑥 + 𝑎2 𝑥 2

Where

𝑎0 = 𝑏0 − 𝑏1 𝑥0 − 𝑏2 𝑥0 𝑥1

𝑎1 = 𝑏1 − 𝑏2 𝑥0 − 𝑏2 𝑥1

𝑎2 = 𝑏2
A simple procedure can be used to determine the values of the coefficients

𝑏0 = 𝑓(𝑥0 ) = 𝑦(𝑥0 )

𝑦(𝑥1 ) − 𝑦(𝑥0 )
𝑏1 =
𝑥1 − 𝑥0

𝑦(𝑥2 ) − 𝑦(𝑥1 ) 𝑦(𝑥1 ) − 𝑦(𝑥0 )



𝑥2 − 𝑥1 𝑥1 − 𝑥0
𝑏2 =
𝑥2 − 𝑥0

Lec. Hussein K. Jobair


5 Chapter Three / Interpolation

3.3.3 General Form of Newton’s Interpolating Polynomials


The preceding analysis can be generalized to fit an nth-order polynomial to
(𝑛 + 1) data points. The nth-order polynomial is
𝑦𝑛 (𝑥) = 𝑏0 + 𝑏1 (𝑥 − 𝑥0 ) + ⋯ + 𝑏𝑛 (𝑥 − 𝑥0 )(𝑥 − 𝑥1 ) … (𝑥 − 𝑥𝑛−1 )
As was done previously with the linear and quadratic interpolations, data
points can be used to evaluate the coefficients 𝑏0 , 𝑏1 , . . . , 𝑏𝑛 . For an nth
order polynomial, n + 1 data points are required:(𝑥0 , 𝑦0 ), (𝑥1 , 𝑦1 ), (𝑥𝑛 , 𝑦𝑛 ).
We use these data points and the following equations to evaluate the
coefficients:
𝑏0 = 𝑓(𝑥0 )

𝑏1 = 𝑓(𝑥1 , 𝑥0 )

𝑏2 = 𝑓(𝑥2 , 𝑥1 , 𝑥0 )

𝑏𝑛 = 𝑓(𝑥𝑛 , 𝑥𝑛−1 , … , 𝑥1 , 𝑥0 )

The bracketed function evaluations are finite divided differences. For


example, the first finite divided difference is represented generally as

𝑓(𝑥𝑖 ) − 𝑓(𝑥𝑗 )
𝑓[𝑥𝑖 , 𝑥𝑗 ] =
𝑥𝑖 − 𝑥𝑗
The second finite divided difference, which represents the difference of
two first divided differences, is expressed generally as
𝑓[𝑥𝑖 − 𝑥𝑗 ] − 𝑓[𝑥𝑗 − 𝑥𝑘 ]
𝑓[𝑥𝑖 , 𝑥𝑗 , 𝑥𝑘 ] =
𝑥𝑖 − 𝑥𝑘

Lec. Hussein K. Jobair


6 Chapter Three / Interpolation

Similarly, the nth finite divided difference is


𝑓[𝑥𝑛 , 𝑥𝑛−1 , … , 𝑥1 ] − 𝑓[𝑥𝑛−1 , 𝑥𝑛−2 , … , 𝑥0 ]
𝑓[𝑥𝑛 , 𝑥𝑛−1 , … , 𝑥1 , 𝑥0 ] =
𝑥𝑛 − 𝑥0

Example (3.2)
Fit a second-order polynomial to the three points used in Example (3.1)

Solution

𝑥0 = 1 𝑦0 = 0

𝑥1 = 4 𝑦1 = 1.386294

𝑥2 = 6 𝑦2 = 1.791759

𝑏0 = 0

𝑦(𝑥1 ) − 𝑦(𝑥0 )
𝑏1 =
𝑥1 − 𝑥0

1.386294 − 0
𝑏1 = = 0.4620981
4−1

𝑦(𝑥2 ) − 𝑦(𝑥1 ) 𝑦(𝑥1 ) − 𝑦(𝑥0 )



𝑥2 − 𝑥1 𝑥1 − 𝑥0
𝑏2 =
𝑥2 − 𝑥0

1.791759 − 1.386294 1.386294 − 0



𝑏2 = 6 − 4 4−1 = −0.0518731
6−1

𝑦2 (𝑥) = 𝑏0 + 𝑏1 (𝑥 − 𝑥0 ) + 𝑏2 (𝑥 − 𝑥0 )(𝑥 − 𝑥1 )
𝑦2 (2) = 0 + 0.4620981(2 − 1) − 0.0518731(2 − 1)(2 − 4)
𝑦2 (2) = 0.5658444

Lec. Hussein K. Jobair


7 Chapter Three / Interpolation

Example (3.3)

In Example (3.2), data points at 𝑥0 = 1, 𝑥1 = 4, and 𝑥2 = 6were used to


estimate 𝑙𝑛 (2) with a parabola. Now, adding a fourth point [𝑥3 =
5; 𝑓 (𝑥3) = 1.609438], estimate 𝑙𝑛 (2) with a third-order Newton’s
interpolating polynomial.
Solution
The third-order polynomial with n = 3, is

𝑦3 (𝑥) = 𝑏0 + 𝑏1 (𝑥 − 𝑥0 ) + 𝑏2 (𝑥 − 𝑥0 )(𝑥 − 𝑥1 ) + 𝑏3 (𝑥 − 𝑥0 )(𝑥 − 𝑥1 )(𝑥


− 𝑥2 )

𝑓(𝑥1 ) − 𝑓(𝑥0 ) 1.386294 − 0


𝑓[𝑥1 , 𝑥0 ] = = = 0.4620981
𝑥1 − 𝑥0 4−1
𝑓(𝑥2 ) − 𝑓(𝑥1 ) 1.791759 − 1.386294
𝑓[𝑥2 , 𝑥1 ] = = = 0.2027326
𝑥2 − 𝑥1 6−4
𝑓(𝑥3 ) − 𝑓(𝑥2 ) 1.609438 − 1.791759
𝑓[𝑥3 , 𝑥2 ] = = = 0.1823216
𝑥3 − 𝑥2 5−6
The second divided differences are
0.2027326 − 0.4620981
𝑓[𝑥2 , 𝑥1 , 𝑥0 ] = = −0.05187311
6−1
0.1823216 − 0.2027326
𝑓[𝑥3 , 𝑥2 , 𝑥1 ] = = −0.02041100
5−4
−0.02041100 − (−0.05187311)
𝑓[𝑥3 , 𝑥2 , 𝑥1 , 𝑥0 ] = = 0.007865529
5−1
The result for 𝑓[𝑥1 , 𝑥0 ], 𝑓[𝑥2 , 𝑥1 , 𝑥0 ], 𝑓[𝑥3 , 𝑥2 , 𝑥1 , 𝑥0 ] represent the
coefficients 𝑏1 , 𝑏2 , 𝑏3 respectively. 𝑏0 = 0, so a third-order Newton’s
interpolating polynomial
𝑦3 (𝑥) = 𝑏0 + 𝑏1 (𝑥 − 𝑥0 ) + 𝑏2 (𝑥 − 𝑥0 )(𝑥 − 𝑥1 ) + 𝑏3 (𝑥 − 𝑥0 )(𝑥 − 𝑥1 )(𝑥
− 𝑥2 )

Lec. Hussein K. Jobair


8 Chapter Three / Interpolation

𝑦2 (2) = 0 + 0.4620981(2 − 1) − 0.05187311(2 − 1)(2 − 4)


+ 0.007865529(2 − 1)(2 − 4)(2 − 6) = 0.6287686
This represents a relative error of 9.3%.

3.3.4 Errors of Newton’s Interpolating Polynomials

Even though the Newton’s Interpolating Polynomials decreases the


percentage error between the calculated and exact value, there is still a
percentage of error. The amount of error for an nth-order interpolating
polynomial can be calculated from the following formula
𝑓 𝑛+1 (𝜉)
𝑅𝑛 = (𝑥 − 𝑥0 )(𝑥 − 𝑥1 ) … (𝑥 − 𝑥2 )
(𝑛 + 1)!
Where ξ is somewhere in the interval containing the unknown and the data.
For this formula to be of use, the function in question must be known and
differentiable. This is not usually the case. Fortunately, an alternative
formulation is available that does not require prior knowledge of the
function. Rather, it uses a finite divided difference to approximate the (n +
1)th derivative
𝑅𝑛 = 𝑓[𝑥, 𝑥𝑛 , 𝑥𝑛−1 , … , 𝑥1 , 𝑥0 ](𝑥 − 𝑥0 )(𝑥 − 𝑥1 ) … (𝑥 − 𝑥𝑛 )
Where 𝑓[𝑥, 𝑥𝑛 , 𝑥𝑛−1 , … , 𝑥1 , 𝑥0 ]is the (n + 1)th finite divided difference.
Because equation above contains the unknown f (x), it cannot be solved for
the error. However, if an additional data point 𝑓(𝑥𝑛 + 1) is available, the
equation above can be used to estimate the error, as in
𝑅𝑛 ≅ 𝑓[𝑥𝑛+1 , 𝑥𝑛 , 𝑥𝑛−1 , … , 𝑥1 , 𝑥0 ](𝑥 − 𝑥0 )(𝑥 − 𝑥1 ) … (𝑥 − 𝑥𝑛 )

Lec. Hussein K. Jobair


9 Chapter Three / Interpolation

Example (3.4)

Estimate the error for the second-order polynomial interpolation of Example


(3.2). Use the additional data point f (𝑥3 ) = f (5) = 1.609438 to obtain the
results.
Solution
The second-order interpolating polynomial provided an estimate of 𝑓 (2) =
0.5658444, which represents an error of 0.6931472 − 0.5658444 =
0.1273028.
𝑅2 = 𝑓[𝑥3 , 𝑥2 , 𝑥1 , 𝑥0 ](𝑥 − 𝑥0 )(𝑥 − 𝑥1 )(𝑥 − 𝑥2 )
𝑅2 = 0.007865529 (2 − 1)(2 − 4)(2 − 6) = 0.0629242
This represents the estimated error at 𝑥 = 2. it should be clear that the error
estimate for the nth-order polynomial is equivalent to the difference between
the (𝑛 + 1)th-order and the nth-order prediction. That is,
𝑅𝑛 = 𝑓𝑛+1 (𝑥) − 𝑓𝑛 (𝑥)

3.4 Lagrange Interpolation


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
𝑛

𝑓𝑛 (𝑥) = ∑ 𝐿𝑖 (𝑥)𝑓(𝑥𝑖 )
𝑖=0
𝑛 𝑥 − 𝑥𝑖
𝐿𝑖 (𝑥) = ∏𝑗=0
𝑥𝑗 − 𝑥𝑖
𝑗≠𝑖

Lec. Hussein K. Jobair


10 Chapter Three / Interpolation

Where Π designates the “product of.” For example, the linear version (n = 1)
is
𝑥 − 𝑥1 𝑥 − 𝑥0
𝑓1 (𝑥) = 𝑓(𝑥0 ) + 𝑓(𝑥1 )
𝑥0 − 𝑥1 𝑥1 − 𝑥0

And the second-order version is

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

Example (3-5)
Use Lagrange interpolating of the first order and second order to evaluate
𝑓(𝑥) at 𝑥 = 2 due to the following data.
𝑥0 = 1 𝑓(𝑥0 ) = 0
𝑥1 = 4 𝑓(𝑥1 ) = 1.3863
𝑥2 = 6 𝑓(𝑥2 ) = 1.7917

Solution:
The first order Lagrange interpolating is
𝑥 − 𝑥1 𝑥 − 𝑥0
𝑓1 (𝑥) = 𝑓(𝑥0 ) + 𝑓(𝑥1 )
𝑥0 − 𝑥1 𝑥1 − 𝑥0
At 𝑥 = 2
2−4 2−1
𝑓1 (2) = ∗0+ ∗ 1.3863
1−4 4−1

∴ 𝑓1 (2) = 0.4621

Lec. Hussein K. Jobair


11 Chapter Three / Interpolation

The second order Lagrange interpolating is


(𝑥 − 𝑥1 )(𝑥 − 𝑥2 ) (𝑥 − 𝑥0 )(𝑥 − 𝑥2 )
𝑓2 (𝑥) = 𝑓(𝑥0 ) + 𝑓(𝑥1 )
(𝑥0 − 𝑥1 )(𝑥0 − 𝑥2 ) (𝑥1 − 𝑥0 )(𝑥1 − 𝑥2 )
(𝑥 − 𝑥0 )(𝑥 − 𝑥1 )
+ 𝑓(𝑥2 )
(𝑥2 − 𝑥0 )(𝑥2 − 𝑥1 )
(2 − 4)(2 − 6) (2 − 1)(2 − 6) (2 − 1)(2 − 4)
𝑓2 (2) = ×0+ × 1.3863 +
(1 − 4)(1 − 6) (4 − 1)(4 − 6) (6 − 1)(6 − 4)
× 1.7917 = 0.5658444
H.W (1)
Compute the value of 𝑙𝑛 9.2 from 𝑙𝑛 9 = 2.1972, 𝑙𝑛 9.5 = 2.2513 by linear
Lagrange interpolation and determine the error, using 𝑙𝑛 9.2 = 2.2192.
H.W (2)
Calculate the Lagrange polynomial 𝑃2 (𝑥) for the values Γ(1.00) =
1.000, Γ(1.02) = 0.988, Γ(1.04) = 0.9784 of the Gamma function, from it
approximations of Γ(1.01)𝑎𝑛𝑑 Γ(1.03).
H.W (3)
From the principles of Newton's divided difference method, drive the linear
Lagrange interpolation formula
𝑥 − 𝑥1 𝑥 − 𝑥0
𝑓1 (𝑥) = 𝑓(𝑥0 ) + 𝑓(𝑥1 )
𝑥0 − 𝑥1 𝑥1 − 𝑥0

3.4 Spline Interpolation

Lec. Hussein K. Jobair


12 Chapter Three / Interpolation

In the previous sections, nth-order polynomials were used to interpolate


between n + l data points. For example, for eight points, we can derive a
perfect seventh-order polynomial. However, there are cases where these
functions can lead to erroneous results because of round-off error and
overshoot. An alternative approach is to apply lower-order polynomials to
subsets of data points. Such connecting polynomials are called spline
functions. For example, third-order curves employed to connect each pair of
data points are called cubic splines. These functions can be constructed so
that the connections between adjacent cubic equations are visually smooth.
I.e. not necessarily the exactness increase with increasing the points.
A famous example by C. Runge for which the maximum error even
approaches ∞ 𝑎𝑠 𝑛 → ∞ with the nodes kept equidistant and their number
increased

Figure (3-2) Runge’s example ƒ(x) = 1/(1+x2) and interpolating


Polynomial P10(x)
Those undesirable oscillations are avoided by the method of splines. This
method is widely used in practice. It also laid the foundation for much of
modern CAD (computer-aided design). Its name is borrowed from a
draftsman's spline, which is an elastic rod bent to pass through given points

Lec. Hussein K. Jobair


13 Chapter Three / Interpolation

and held in place by weights. The mathematical idea of this method divided
into three types

1- Linear Spline

The simplest connection between two points is a straight line. The first-order
splines for a group of ordered data points can be defined as a set of linear
functions
𝑓(𝑥) = 𝑓(𝑥0 ) + 𝑚0 (𝑥 − 𝑥0 ) 𝑥0 ≤ 𝑥 ≤ 𝑥1
𝑓(𝑥) = 𝑓(𝑥1 ) + 𝑚1 (𝑥 − 𝑥1 ) 𝑥1 ≤ 𝑥 ≤ 𝑥2
.
.
.
𝑓(𝑥) = 𝑓(𝑥𝑛−1 ) + 𝑚𝑛−1 (𝑥 − 𝑥𝑛−1 ) 𝑥𝑛−1 ≤ 𝑥 ≤ 𝑥𝑛
Where mi is the slope of the straight line connecting the points:

𝑓(𝑥𝑖+1 ) − 𝑓(𝑥𝑖 )
𝑚𝑖 =
𝑥𝑖+1 − 𝑥𝑖

These equations can be used to evaluate the function at any point between x0
and xn by first locating the interval within which the point lies. Then the
appropriate equation is used to determine the function value within the
interval. The method is obviously identical to linear interpolation.

Lec. Hussein K. Jobair


14 Chapter Three / Interpolation

Example (3.6)
Fit the data in Table below with first-order splines. Evaluate the function at
𝑥=5
𝑋 𝐹(𝑥)
3.0 2.5
4.5 1.0
7.0 2.5
9.0 0.5

Solution
The data can be used to determine the slopes between points. For example,
for the interval 𝑥 = 4.5 to 𝑥 = 7 the slope can be computed
2.5 − 1
𝑚= = 0.6
7 − 4.5
The slopes for the other intervals can be computed, and the resulting first-
order splines are plotted in figure (3.3). The value at x = 5 is 1.3
Visual inspection of figure (3.3a) indicates that the primary disadvantage of
first-order splines is that they are not smooth. In essence, the slope changes
abruptly. In formal terms, the first derivative of the function is discontinuous
at these points. This deficiency is overcome by using higher-order
polynomial splines that ensure smoothness by equating derivatives at these
points, as discussed in the next section.

Lec. Hussein K. Jobair


15 Chapter Three / Interpolation

Figure (3.3) Spline fits of a set of four points. (a) Linear spline, (b)
quadratic spline, and (c) cubic spline, with a cubic interpolating
polynomial also plotted

Lec. Hussein K. Jobair


16 Chapter Three / Interpolation

2- Quadratic spline
To ensure that the nth derivatives are continuous at the points, a spline of at
least 𝑛 + 1 order must be used. Third-order polynomials or cubic splines
that ensure continuous first and second derivatives are most frequently used
in practice.
Because the derivation of cubic splines is somewhat involved, we have
chosen to include them in a subsequent section. We have decided to first
illustrate the concept of spline interpolation using second-order polynomials.
These “quadratic splines” have continuous first derivatives at the points.
Although quadratic splines do not ensure equal second derivatives at the
points, they serve nicely to demonstrate the general procedure for
developing higher-order splines.
The objective in quadratic splines is to derive a second-order polynomial for
each interval between data points. The polynomial for each interval can be
represented generally as
𝑓𝑖 (𝑥) = 𝑎𝑖 𝑥 2 + 𝑏𝑖 𝑥 + 𝑐𝑖
Figure (3.4) has been included to help clarify the notation. Notice that there
are (𝑛) intervals and (𝑛 + 1) data points. The example shown in the figure
is for 𝑛 = 3.
For n + 1 data points (i = 0, 1, 2, . . . , n), there are n intervals and,
consequently, 3n unknown constants (the a’s, b’s, and c’s) to evaluate.
Therefore, 3n equations or conditions are required to evaluate the
unknowns. These are:

1- The function values of adjacent polynomials must be equal at the


interior knots. This condition can be represented as
2
𝑎𝑖−1 𝑥𝑖−1 + 𝑏𝑖−1 𝑥𝑖−1 + 𝑐𝑖−1 = 𝑓(𝑥𝑖−1 )

Lec. Hussein K. Jobair


17 Chapter Three / Interpolation

2
𝑎𝑖 𝑥𝑖−1 + 𝑏𝑖 𝑥𝑖−1 + 𝑐𝑖 = 𝑓(𝑥𝑖−1 )

Figure (3.4) Notation used to derive quadratic splines

2- The first and last functions must pass through the end points. This
adds two additional equations:
𝑎1 𝑥02 + 𝑏1 𝑥0 + 𝑐1 = 𝑓(𝑥0 )
𝑎𝑛 𝑥𝑛2 + 𝑏𝑛 𝑥𝑛 + 𝑐𝑛 = 𝑓(𝑥𝑛 )
3- The first derivatives at the interior knots must be equal
𝑓 ′ (𝑥) = 2𝑎𝑥 + 𝑏
Therefore, the condition can be represented generally as

2𝑎𝑛−1 𝑥𝑛−1 + 𝑏𝑛−1 = 2𝑎𝑖 𝑥𝑖−1 + 𝑏𝑖

4- Assume that the second derivative is zero at the first point. Because
the second derivative is 2ai this condition can be expressed
mathematically as

Lec. Hussein K. Jobair


18 Chapter Three / Interpolation

𝑎1 = 0
The visual interpretation of this condition is that the first two points will be
connected by a straight line.
Example (3.7)
Fit quadratic splines to the same data used in Example (3.6). Use the results
to estimate the value at x = 5.
Solution
For the present problem, we have four data points and 𝑛 = 3 intervals.
Therefore, 3(3) = 9 unknowns must be determined. And 2(3) − 2 = 4
conditions
20.25𝑎1 + 4.5𝑏1 + 𝑐1 = 1.0
20.25𝑎2 + 4.5𝑏2 + 𝑐2 = 1.0
49𝑎2 + 7𝑏2 + 𝑐2 = 2.5
49𝑎3 + 7𝑏3 + 𝑐3 = 2.5
Passing the first and last functions through the initial and final values adds 2
more
9𝑎1 + 3𝑏1 + 𝑐1 = 2.5
81𝑎3 + 9𝑏3 + 𝑐3 = 0.5
Continuity of derivatives creates an additional 3 − 1 = 2
9𝑎1 + 𝑏1 = 9𝑎2 + 𝑏2
14𝑎2 + 𝑏2 = 14𝑎3 + 𝑏3
Finally, a1= 0. Because we know the value of a1 exactly, the problem
reduces to solving eight simultaneous equations. These conditions can be
expressed in matrix form as

Lec. Hussein K. Jobair


19 Chapter Three / Interpolation

These equations can be solved by using any method for solving a system of
simultaneous linear equations in chapter one
𝑎1 = 0 𝑏1 = −1 𝑐1 = 5.5
𝑎2 = 0.64 𝑏2 = −6.76 𝑐2 = 18.46
𝑎3 = −1.6 𝑏3 = 24.6 𝑐3 = −91.3
Which can be substituted into the original quadratic equations to develop the
following relationships for each interval:
𝑓1 (𝑥) = −𝑥 + 5.5 3.0 ≤ 𝑥 ≤ 4.5
𝑓2 (𝑥) = 0.64𝑥 2 − 6.7𝑥 + 18.46 4.5 ≤ 𝑥 ≤ 7.0
𝑓3 (𝑥) = −1.6𝑥 2 + 24.6𝑥 − 91.3 7.0 ≤ 𝑥 ≤ 9.0
When we use 𝑓2 , the prediction for 𝑥 = 5 is, therefore,

𝑓2 (5) = 0.64(5)2 − 6.7(5) + 18.46 = 0.66


The total spline fit is depicted in figure (3.3b). Notice that there are two
shortcomings that detract from the fit: (1) the straight line connecting the
first two points and (2) the spline for the last interval seems to swing too
high. The cubic splines in the next section not exhibit these shortcomings
and, as a consequence, are better methods for spline interpolation.

Lec. Hussein K. Jobair


20 Chapter Three / Interpolation

3- Cubic spline
The objective in cubic splines is to derive a third-order polynomial for each
interval between knots, as in
𝑓𝑖 (𝑥) = 𝑎𝑖 𝑥 3 + 𝑏𝑖 𝑥 2 + 𝑐𝑖 𝑥 + 𝑑𝑖
Thus, for n + 1 data points (i = 0, 1, 2, . . . , n), there are n intervals and,
consequently, 4n unknown constants to evaluate. Just as for quadratic
splines, 4n conditions are required to evaluate the unknowns. These are:
A. The function values must be equal at the interior knots (2n − 2
conditions).
B. The first and last functions must pass through the end points (2
conditions).
C. The first derivatives at the interior knots must be equal (n − 1
conditions).
D. The second derivatives at the interior knots must be equal (n − 1
conditions).
E. The second derivatives at the end knots are zero (2 conditions).
The visual interpretation of condition 5 is that the function becomes a
straight line at the end knots. Specification of such an end condition leads to
what is termed a “natural” spline. It is given this name because the drafting
spline naturally behaves in this fashion figure (3.5). If the value of the
second derivative at the end knots is nonzero (that is, there is some
curvature), this information can be used alternatively to supply the two final
conditions.

Lec. Hussein K. Jobair


21 Chapter Three / Interpolation

Figure (3.5) the drafting technique of using a spline to draw smooth


curves through a series of points. Notice how, at the end points, the
spline straightens out. This is called a “natural” spline
The above five types of conditions provide the total of 4n equations required
to solve for the 4n coefficients. Whereas it is certainly possible to develop
cubic splines in this fashion, we will present an alternative technique that
requires the solution of only n − 1 equations.
The first step in the derivation is based on the observation that because each
pair of knots is connected by a cubic, the second derivative within each
interval is a straight line. The equation below
𝑓𝑖 (𝑥) = 𝑎𝑖 𝑥 3 + 𝑏𝑖 𝑥 2 + 𝑐𝑖 𝑥 + 𝑑𝑖 (A-3)
Can be differentiated twice to verify this observation. On this basis, the
second derivatives can be represented by a first-order Lagrange interpolating
polynomial
𝑥 − 𝑥𝑖 𝑥 − 𝑥𝑖−1
𝑓𝑖′′ (𝑥) = 𝑓𝑖′′ (𝑥𝑖−1 ) + 𝑓𝑖′′ (𝑥𝑖 )
𝑥𝑖−1 − 𝑥𝑖 𝑥𝑖 − 𝑥𝑖−1
Where 𝑓𝑖′′ (𝑥) is the value of the second derivative at any point x within the
ith interval. Thus, this equation is a straight line connecting the second

Lec. Hussein K. Jobair


22 Chapter Three / Interpolation

derivative at the first knot 𝑓𝑖′′ (𝑥𝑖−1 ) with the second derivative at the second
knot 𝑓𝑖′′ (𝑥).
Next, the equation above can be integrated twice to yield an expression for
fi(x). However, this expression will contain two unknown constants of
integration. These constants can be evaluated by invoking the function-
equality conditions 𝑓(𝑥) must equal 𝑓(𝑥𝑖−1 ) at 𝑥𝑖−1 and f (x) must equal f
(𝑥𝑖 ) at 𝑥𝑖 . By performing these evaluations, the following cubic equation
results:
𝑓𝑖′′ (𝑥𝑖−1 ) 𝑓𝑖′′ (𝑥𝑖 ) 𝑓(𝑥𝑖−1 )
𝑓𝑖 (𝑥) = (𝑥𝑖 − 𝑥)3 + (𝑥 − 𝑥𝑖−1 )3 + [ −
6(𝑥𝑖 −𝑥𝑖−1 ) 6(𝑥𝑖 −𝑥𝑖−1 ) 𝑥𝑖 −𝑥𝑖−1

𝑓′′ (𝑥𝑖−1 )(𝑥𝑖 −𝑥𝑖−1 ) 𝑓(𝑥𝑖 ) 𝑓′′ (𝑥𝑖 )(𝑥𝑖 −𝑥𝑖−1 )


] (𝑥𝑖 − 𝑥) + [ − ] (𝑥 − 𝑥𝑖−1 ) (B-3)
6 𝑥𝑖 −𝑥𝑖−1 6

Now, admittedly, this relationship is a much more complicated expression


for the cubic spline for the ith interval than equation (A-3). However, notice
that it contains only two unknown “coefficients,” the second derivatives at
the beginning and the end of the interval 𝑓 ′′ (𝑥𝑖−1 ) and 𝑓 ′′ (𝑥𝑖 ). Thus, if we
can determine the proper second derivative at each knot, equation (B-3) is a
third-order polynomial that can be used to interpolate within the interval.
The second derivatives can be evaluated by invoking the condition that the
first derivatives at the knots must be continuous:
𝑓𝑖′ (𝑥𝑖 ) = 𝑓𝑖+1

(𝑥𝑖 ) (C-3)
Equation (B-3) can be differentiated to give an expression for the first
derivative. If this is done for both the (𝑖 − 1)th and the 𝑖th intervals and the
two results are set equal according to equation (C-3) the following
relationship results:
(𝑥𝑖 − 𝑥𝑖−1 )𝑓 ′′ (𝑥𝑖−1 ) + 2(𝑥𝑖+1 − 𝑥𝑖−1 )𝑓 ′′ (𝑥𝑖 ) + (𝑥𝑖+1 − 𝑥𝑖 )𝑓 ′′ (𝑥𝑖+1 ) =
6 6
[𝑓(𝑥𝑖+1 ) − 𝑓(𝑥𝑖 )] + [𝑓(𝑥𝑖−1 ) − 𝑓(𝑥𝑖 )] (D-3)
𝑥𝑖+1 −𝑥𝑖 𝑥𝑖 −𝑥𝑖−1

Lec. Hussein K. Jobair


23 Chapter Three / Interpolation

If equation (D-3) is written for all interior knots, n − 1 simultaneous


equations result with n + 1 unknown second derivatives. However, because
this is a natural cubic spline, the second derivatives at the end knots are zero
and the problem reduces to n − 1 equations with n − 1 unknowns. In
addition, notice that the system of equations will be tridiagonal. Thus, not
only have we reduced the number of equations but we have also cast them in
a form that is extremely easy to solve.
The derivation from the above results in the following cubic equation for
each interval:
𝑓𝑖′′ (𝑥𝑖−1 ) 𝑓𝑖′′ (𝑥𝑖 ) 𝑓(𝑥𝑖−1 )
𝑓𝑖 (𝑥) = (𝑥𝑖 − 𝑥)3 + (𝑥𝑖−1 − 𝑥)3 + [ −
6(𝑥𝑖 −𝑥𝑖−1 ) 6(𝑥𝑖 −𝑥𝑖−1 ) 𝑥𝑖 −𝑥𝑖−1

𝑓′′ (𝑥𝑖−1 )(𝑥𝑖 −𝑥𝑖−1 ) 𝑓(𝑥𝑖 ) 𝑓′′ (𝑥𝑖 )(𝑥𝑖 −𝑥𝑖−1 )


] (𝑥𝑖 − 𝑥) + [ − ] (𝑥 − 𝑥𝑖−1 ) (E-3)
6 𝑥𝑖 −𝑥𝑖−1 6

This equation contains only two unknowns, the second derivatives at the end
of each interval. These unknowns can be evaluated using the following
equation:
𝑓 ′′ (𝑥𝑖−1 )(𝑥𝑖 − 𝑥𝑖−1 ) + 2𝑓 ′′ (𝑥𝑖 )(𝑥𝑖+1 − 𝑥𝑖−1 ) + 𝑓 ′′ (𝑥𝑖+1 )(𝑥𝑖+1 − 𝑥𝑖 ) =
6 6
[𝑓(𝑥𝑖+1 ) − 𝑓(𝑥𝑖 )] + [𝑓(𝑥𝑖−1 ) − 𝑓(𝑥𝑖 )] (D-3)
𝑥𝑖+1 −𝑥𝑖 𝑥𝑖 −𝑥𝑖−1

If this equation is written for all the interior knots, n − 1 simultaneous


equations result with n − 1 unknowns. (Remember, the second derivatives at
the end knots are zero.) The application of these equations is illustrated in
the following example.

Lec. Hussein K. Jobair


24 Chapter Three / Interpolation

Example (3.8)
Fit cubic splines to the same data used in examples (3.6). Utilize the results
to estimate the value at x = 5.
Solution
The first step is to employ equation (D-3) to generate the set of simultaneous
equations that will be utilized to determine the second derivatives at the
knots. For example, for the first interior knot, the following data is used:
𝑥0 = 3 𝑓(𝑥0 ) = 2.5
𝑥1 = 4.5 𝑓(𝑥1 ) = 1
𝑥2 = 7 𝑓(𝑥2 ) = 2.5
These values can be substituted into equation (E-3) to yield

𝑓 ′′ (3)(4.5 − 3) + 2𝑓 ′′ (4.5)(7 − 3) + 𝑓 ′′ (7)(7 − 4.5)


6 6
= [2.5 − 1] + [2.5 − 1]
7 − 4.5 4.5 − 3

Because of the natural spline condition, 𝑓 ′′ (3) = 0, and the equation


reduces to

8𝑓 ′′ (4.5) + 2.5𝑓 ′′ (7) = 9.6

In a similar fashion, equation (D-3) can be applied to the second interior


point to give
2.5𝑓 ′′ (4.5) + 9𝑓 ′′ (7) = −9.6

These two equations can be solved simultaneously for

𝑓 ′′ (4.5) = 1.67909
𝑓 ′′ (7) = −1.53308

These values can then be substituted into equation (D-3), along with values
for the x’s and the f (x)’s, to yield

Lec. Hussein K. Jobair


25 Chapter Three / Interpolation

1.67909 2.5
𝑓1 (𝑥) = (𝑥 − 3)3 + (4.5 − 𝑥)
6(4.5 − 3) 4.5 − 3
1 1.67909(4.5 − 3)
+[ − ] (𝑥 − 3)
5.4 − 3 6
Or
𝑓1 (𝑥) = 0.186566(𝑥 − 3)3 + 1.666667(4.5 − 𝑥) + 0.246894(𝑥 − 3)
This equation is the cubic spline for the first interval. Similar substitutions
can be made to develop the equations for the second and third intervals:
𝑓2 (𝑥) = 0.111939(7 − 𝑥)3 − 0.102205(𝑥 − 4.5)3 − 0.299621(7 − 𝑥)
+ 1.638783(𝑥 − 4.5)
And
𝑓3 (𝑥) = −.127757(9 − 𝑥)3 + 1.761027(9 − 𝑥) + 0.25(𝑥 − 7)
The three equations can then be employed to compute values within each
interval. For example, the value at x = 5, which falls within the second
interval, is calculated as
𝑓2 (𝑥) = 0.111939(7 − 5)3 − 0.102205(5 − 4.5)3 − 0.299621(7 − 5)
+ 1.638783(5 − 4.5) = 1.102886
The results of examples (3.6) through (3.8) are summarized in figure (3.3).
Notice the progressive improvement of the fit as we move from linear to
quadratic to cubic splines. We have also superimposed a cubic interpolating
polynomial on figure (3.3c). Although the cubic spline consists of a series of
third-order curves, the resulting fit differs from that obtained using the third-
order polynomial. This is due to the fact that the natural spline requires zero
second derivatives at the end knots, whereas the cubic polynomial has no
such constraint.

Lec. Hussein K. Jobair


26 Chapter Three / Interpolation

H.W (4)

Develop quadratic splines for the data in the table below and predict f (3.4)
and f (2.2).
𝑥 𝐹(𝑥)
1.6 2
2 8
2.5 14
3.2 15
4 8

H.W (5)

Develop cubic splines for the data given below and (a) predict 𝑓 (4) and
𝑓 (2.5) and (b) verify that 𝑓2 (3) and 𝑓3 (3) = 19.

𝑥 𝐹(𝑥)
1 3
2 6
3 19
5 99
7 291
8 444

Lec. Hussein K. Jobair

You might also like