Professional Documents
Culture Documents
Department of Mathematics
Indian Institute of Technology Delhi
Dr. Mani Mehra (IIT Delhi) Numerical Analysis : MTL851 March 20, 2023 1 / 53
Interpolation
Interpolation methods are the basis for many other procedures that you will
study in this course, such as numerical integration and differentiation.
They are behind the ways that we use to solve ordinary and partial
differential equations.
They demonstrate important theory about polynomials and the accuracy of
numerical methods.
They are one of the more important ways that curves are drawn on your
computer screen.
There is a rich history behind interpolation. It really began with the early
studies of astronomy when the motion of heavenly bodies was determined
from periodic observations.
An application of interpolation that you see every day is in weather
forecasting. When you watch the weather forecasts on television, you may
wonder where these (usually) correct projections come from.
Dr. Mani Mehra (IIT Delhi) Numerical Analysis : MTL851 March 20, 2023 2 / 53
Interpolating Polynomials
Dr. Mani Mehra (IIT Delhi) Numerical Analysis : MTL851 March 20, 2023 3 / 53
Interpolating Polynomials
First, we need to select the points that determine our polynomial. The
maximum degree of the polynomial is always one less than the number of
points. Suppose we choose the first four points. If the cubic is
ax 3 + bx 2 + cx + d, we can write four equations involving the unknown
coefficients a, b, c, and d.
Dr. Mani Mehra (IIT Delhi) Numerical Analysis : MTL851 March 20, 2023 4 / 53
if x = 3.2 : a(3.2)3 + b(3.2)2 + c(3.2) + d = 22.0
if x = 2.7 : a(2.7)3 + b(2.7)2 + c(2.7) + d = 17.8
if x = 1.0 : a(1.0)3 + b(1.0)2 + c(1.0) + d = 14.2
if x = 4.8 : a(4.8)3 + b(4.8)2 + c(4.8) + d = 38.3
Dr. Mani Mehra (IIT Delhi) Numerical Analysis : MTL851 March 20, 2023 5 / 53
Lagrangian Polynomials
We will first look at one very straightforward approach-the Lagrangian
polynomial. The Lagrangian polynomial is perhaps the simplest way to
exhibit the existence of a polynomial for interpolation with unevenly spaced
data. Data where the x-values are non equispaced often occur as the result
of experimental observations or when historical data are examined.
We want to construct a polynomial Pn (x) of degree n that passes through
(n + 1) points. Consider the polynomial
(x − x0 )(x − x1 ) · · · (x − xk−1 )(x − xk+1 ) · · · (x − xn )
Pn,k (x) = .
(xk − x0 )(xk − x1 ) · · · (xk − xk−1 )(xk − xk+1 ) · · · (xk − xn )
We observe from above, Pn,k (x) is a polynomial of degree n,
Pn,k (xi ) = 0, i 6= k and Pn,k (xk ) = 1. So based on these properties:
n
X
Pn (x) = yk Pn,k (x),
k=0
from the above we observe that Pn (xi ) = yi . The function Pn,k (x) is called
the Lagrange fundamental polynomials and Pn (x) is the Lagrange
Dr. polynomial.
Mani Mehra (IIT Delhi) Numerical Analysis : MTL851 March 20, 2023 6 / 53
Example
Consider the following data:
Dr. Mani Mehra (IIT Delhi) Numerical Analysis : MTL851 March 20, 2023 7 / 53
Any polynomial of degree n passes through (n + 1) points is unique.
To prove above, we assume that there is another polynomial Qn (x) and
consider the polynomial
Since Pn (x) and Qn (x) are both polynomials of degree ≤ n, then T (x) is
also a polynomial of degree ≤ n satisfying the conditions
Dr. Mani Mehra (IIT Delhi) Numerical Analysis : MTL851 March 20, 2023 8 / 53
Error of Interpolation
When we fit a polynomial Pn (x) to some data points, it will pass exactly
through those points, but between those points Pn (x) will not be precisely
the same as the function f (x) that generated the points (unless the function
is that polynomial). How much is Pn (x) different from f (x)? How large is
the error of Pn (x)?
We can write error function as
En (x) = f (x) − Pn (x) = (x − x0 )(x − x1 ) · · · (x − xn )g (x).
Dr. Mani Mehra (IIT Delhi) Numerical Analysis : MTL851 March 20, 2023 9 / 53
Note in particular that x has not been replace by t in the g (x) portion. W
is really a function of t and x but we are only interested in variations of t.
We now examine the zeros of W (t). Certainly at t = x0 , x1 , · · · , xn the W
function is zero, but it also zero if t = x there are then a total of n + 2
values of t that makes W (t) = 0.
We now impose the necessary requirements on W(t) for the law of mean
value to hold. W(t) must be continuous and differentiable. If this is so,
there is a zero to its derivative W 0 (t) between each of the n + 2 zeros of
W (t), a total number of n + 1 zeros. Similarly W n+1 (t), which must have
at least one zero in the interval that has x0 , xn or x as endpoints. Call this
value of t = ξ. We then have,
d n+1
W n+1 (ξ) = 0 = [f (t) − Pn (t) − (t − x0 )(t − x1 ) · · · (t − xn )g (x)]|t=ξ
dt n+1
= f n+1 (ξ) − (n + 1)!g (x),
So,
f n+1 (ξ)
g (x) = .
(n + 1)!
Dr. Mani Mehra (IIT Delhi) Numerical Analysis : MTL851 March 20, 2023 10 / 53
We now have our error term
f n+1 (ξ)
En (x) = (x − x0 )(x − x1 ) · · · (x − xn ) ,
(n + 1)!
Example
Using sin(0.1) = 0.09983 and sin(0.2) = 0.19867, find an approximate value of
sin(0.15) by Lagrange interpolation. Obtain abound on the truncation error.
Dr. Mani Mehra (IIT Delhi) Numerical Analysis : MTL851 March 20, 2023 11 / 53
Divided Differences
There are two disadvantages to using the Lagrangian polynomial for
interpolation. First, it involves more arithmetic operations than does the
divided-difference method we now discuss. Second, and more importantly, if
we desire to add or subtract a point from the set used to construct the
polynomial, we essentially have to start over in the computations.
Consider the nth-degree polynomial written in a special way:
Pn (x) = a0 +(x −x0 )a1 +(x −x0 )(x −x1 )a2 +· · ·+(x −x0 )(x −x1 ) · · · (x −xn )an .
If we chose the ai so that Pn (x) = f (x) at the (n + 1) known points,
(xi , fi ), i = 0, · · · , n, then Pn (x) is an interpolating polynomial. Where ai is
readily determined by using what are called the divided differences of the
tabulated values.
A special standard notation for divided differences is
f1 − f0
f [x0 , x1 ] = ,
x1 − x0
called the first divided difference between x0 and x1 .
Dr. Mani Mehra (IIT Delhi) Numerical Analysis : MTL851 March 20, 2023 12 / 53
In general,
ft − fs
f [xs , xt ] = ,
xt − xs
is the first divided difference between xs and xt . Observe that the order of
the points is immaterial:
ft − fs fs − ft
f [xs , xt ] = = = f [xt , xs ].
xt − xs xs − xt
Dr. Mani Mehra (IIT Delhi) Numerical Analysis : MTL851 March 20, 2023 13 / 53
Example
Consider the following data:
Write the interpolating polynomial of degree-3 that fits the data of above Table
at all points from x0 = 3.2 to x3 = 4.8.
Solution:
Dr. Mani Mehra (IIT Delhi) Numerical Analysis : MTL851 March 20, 2023 14 / 53
Spline
Dr. Mani Mehra (IIT Delhi) Numerical Analysis : MTL851 March 20, 2023 15 / 53
As you can observed from figure, the slopes are discontinuous where the
segments join. Splines of degree greater than 1 do not have this problem.
Most often cubic splines are used.
The Equation for a Cubic Spline :We will create a succession of cubic
splines over successive intervals of the data. (There is no requirement that
the points be evenly spaced). Each spline must join with its neighboring
cubic polynomials at the knots where they join with the same slope and
curvature. (The end splines have only one neighbor, so their slope and
curvature is not so constrained.)
Dr. Mani Mehra (IIT Delhi) Numerical Analysis : MTL851 March 20, 2023 16 / 53
We write the equation for a cubic polynomial, gi (x), in the ith interval,
between points (xi , yi ), (xi+l , yi+1 ). It looks like the solid curve shown here.
The dashed curves are other cubic spline polynomials. It has this equation:
gi (x) = ai (x − xi )3 + bi (x − xi )2 + ci (x − xi ) + di
Thus, the cubic spline function we want is of the from g (x) = gi (x) on the
interval [xi , xi+1 ] for i = 0, 1, · · · , n − 1. and meet these conditions:
a) gi (xi ) = yi , i = 0, · · · , n − 1 and gn−1 (xn ) = yn .
b) gi (xi+1 ) = gi+1 (xi+1 ), i = 0, 1, · · · , n − 2
c) gi0 (xi+1 ) = gi+1
0
(xi+1 ), i = 0, 1, · · · , n − 2
00 00
d) gi (xi+1 ) = gi+1 (xi+1 ), i = 0, 1, · · · , n − 2
Dr. Mani Mehra (IIT Delhi) Numerical Analysis : MTL851 March 20, 2023 17 / 53
If there n + 1 points, the number of intervals and the number of gi (x) are n.
Thus there are four times n unknowns, which are the [ai , bi , ci , di ] for
i = 0, 1, · · · , n − 1. Condition (a) immediately gives
di = yi , i = 0, 1, · · · , n − 1.
Condition (b) then gives
yi+1 = gi+1 (xi+1 ) = gi (xi+1 )
= ai (xi+1 − xi )3 + bi (xi+1 − xi )2 + ci (xi+1 − xi ) + yi
= ai hi3 + bi hi2 + ci hi + yi ,
where hi = xi+1 − xi . To relate the slopes and curvatures of the joining,
gi0 (x) = 3ai (x − xi )2 + 2bi (x − xi ) + ci ,
gi00 (x) = 6ai (x − xi ) + 2bi , i = 0, 1, · · · , n − 1.
Let Si = gi00 (xi ) and Sn = gn−1
00
(xn ). We have
Si = 6ai (xi − xi ) + 2bi = 2bi , Si+1 = 6ai (xi+1 − xi ) + 2bi = 6ai hi + 2bi ,
Hence we can write
Si Si+1 − Si
bi = , ai =
2 6hi
Dr. Mani Mehra (IIT Delhi) Numerical Analysis : MTL851 March 20, 2023 18 / 53
We using the value of ai , bi , di and solve for ci we get
yi+1 − yi 2hi Si + hi Si+1
ci = − .
hi 6
We now invoke the condition that the slopes of the two cubic that join at
(xi , yi ) are the same. For the equation in the ith interval, condition (c)
becomes, with x = xi ,
yi0 = 3ai (xi − xi )2 + 2bi (xi − xi ) + ci = ci
In the previous interval, from xi−1 to xi , the slope at its right end will be
yi0 = 3ai−1 (xi −xi−1 )2 +2bi−1 (xi −xi−1 )+ci−1 = 3ai−1 hi−1
2
+2bi−1 hi−1 +ci−1 .
Equating these, and substituting for ai , bi , ci , di their relationship in terms of
S and y we get
yi+1 − yi 2hi Si + hi Si+1
yi0 = −
hi 6
S − S S yi − yi−1 2hi−1 Si−1 + hi−1 Si
i i−1 2 i−1
=3 hi−1 +2 hi−1 + −
6hi−1 2 hi−1 6
Dr. Mani Mehra (IIT Delhi) Numerical Analysis : MTL851 March 20, 2023 19 / 53
Simplifying this equation, we get
y − y yi − yi−1
i+1 i
hi−1 Si−1 + (2hi−1 + 2hi )Si + hi Si+1 = 6 −
hi hi−1
= 6(f [xi , xi+1 ] − f [xi−1 , xi+1 ]).
Dr. Mani Mehra (IIT Delhi) Numerical Analysis : MTL851 March 20, 2023 20 / 53
Take S0 = S1 ,Sn = Sn−1 . This is equivalent to assuming that the end
cubics approach parabolas at their extremities.
Take S0 as a linear extrapolation from S1 and S2 , and Sn , as a linear
extrapolation from Sn−2 and Sn−2 . Only this condition gives cubic
spline curves that match exactly to f (x) when f (x) is itself a cubic.
For condition (d), we use these relations:
(h0 + h1 )S1 − h0 S2
At left end : S0 =
h1
(hn−2 + hn−1 )Sn−1 − hn−1 Sn−2
At right end: Sn = .
hn−2
Dr. Mani Mehra (IIT Delhi) Numerical Analysis : MTL851 March 20, 2023 21 / 53
Example
Fit the given data with a natural cubic spline curve, and evaluate the spline values
g (0.66) and g (1.75).
Dr. Mani Mehra (IIT Delhi) Numerical Analysis : MTL851 March 20, 2023 23 / 53
The coordinate functions φi (x) are usually chosen as
φi (x) = x i , i = 0, 1, · · · , n
and W (x) = 1.
The necessary conditions for error function I will be minimum is that
∂I
= 0, i = 0, 1, · · · , n.
∂ci
Dr. Mani Mehra (IIT Delhi) Numerical Analysis : MTL851 March 20, 2023 24 / 53
Example
Obtain a linear polynomial approximation to the function f (x) = x 3 on the
interval [0, 1] using the least square approximation with W (x) = 1.
Dr. Mani Mehra (IIT Delhi) Numerical Analysis : MTL851 March 20, 2023 25 / 53
Example
Find the least squares approximation of second degree for the discrete data
x -2 -1 0 1 2
f (x) 15 1 1 3 19
Dr. Mani Mehra (IIT Delhi) Numerical Analysis : MTL851 March 20, 2023 26 / 53
Non-Linear Data
In many cases, of course, data from experimental tests are not linear, so we
need to fit to them some function other than a first-degree polynomial.
Popular forms that are tried are the exponential form
y = ax b or y = ae bx
ln y = ln a + b ln x or ln y = ln a + bx.
Dr. Mani Mehra (IIT Delhi) Numerical Analysis : MTL851 March 20, 2023 27 / 53
Use of Orthogonal Polynomials
System of normal equations for a polynomial fit is ill conditioned when the
degree is high. Even for a cubic least-squares polynomial, the condition
number of the coefficient matrix can be large.
In one experiment, [Atkinson (1985)] a cubic polynomial was fitted to 21
data points. When the data were put into the coefficient matrix of normal
equations, its condition number (using 2-norms) was found to be 22,000!
This means that small differences in the y -values will make a large difference
in the solution.
However, if we fit the data with orthogonal polynomials such as the
Chebyshev polynomials, the condition number of the coefficient matrix is
reduced to about 5 and the solution is not much affected by the
perturbations.
Next, we will discuss about well known orthogonal polynomials, Legendre
polynomials and Chebyshev polynomials.
Dr. Mani Mehra (IIT Delhi) Numerical Analysis : MTL851 March 20, 2023 28 / 53
Legendre Polynomials
The Legendre polynomials Pn (x) defined on [−1, 1] are given by
M
X (2n − 2m)!x n−2m
Pn (x) = (−1)m ,
m=0
2n m!(n − m)!(n − 2m)!
Dr. Mani Mehra (IIT Delhi) Numerical Analysis : MTL851 March 20, 2023 29 / 53
Legendre polynomials possess the following properties:
1) Pn (x) is an even polynomial if n is even and an odd polynomial if n is
odd.
2) Pn (x) are orthogonal polynomials and satisfy
Z 1 (
0 m 6= n
Pm (x)Pn (x)dx = 2
−1 2n+1 m = n.
3) Pn (−x) = (−1)n Pn (x).
Chebyshev Polynomials : The Chebyshev polynomials of the first
kind Tn (x) defined on [−1, 1] are given by
Tn (x) = cos(n cos−1 x) = cos nθ,
where θ = cos−1 x or x = cos θ.
These polynomials satisfy the differential equation (DE)
(1 − x 2 )y 00 − xy 0 + n2 y = 0.
One independent solution of the above DE gives Tn (x) and second one gives
Chebyshev polynomials of the second kind Un (x)
Un (x) = sin[(n + 1) cos−1 x]
Dr. Mani Mehra (IIT Delhi) Numerical Analysis : MTL851 March 20, 2023 30 / 53
The Chebyshev polynomials Tn (x) satisfy the recurrence relation
Dr. Mani Mehra (IIT Delhi) Numerical Analysis : MTL851 March 20, 2023 31 / 53
Example
Using the Chebyshev polynomials, obtain the least squares approximation of
second degree for f (x) = x 4 on [−1, 1].
Dr. Mani Mehra (IIT Delhi) Numerical Analysis : MTL851 March 20, 2023 32 / 53