Professional Documents
Culture Documents
srvprasad.bh@gmail.com
srvprasad.bh@vit.ac.in
Interpolation of Non Equi-space Data Points
1
Introduction
I Till now we have discussed the interpolation techniques for estimating
the missing data when the data points are equi-spaced.
I But, in many cases the data points are not equi-spaced.
I In this case, we can not use the Newton’s forward/backward or
Striling’s interpolation techniques.
I We should go for other techniques for solving these non-equispaced
data sets.
Introduction
I In next few classes we will discuss various methods of interpolation.
They include:
1. Lagrange interpolation
2. Newton’s divided difference interpolation
3. Spline interpolation
Polynomials
I A polynomial is an expression of finite length constructed from
variables (also called indeterminates) and constants, using only the
operations of addition, subtraction, multiplication, and non-negative
integer exponents.
I The most common form of an nth order polynomial is:
y = Pn (x) = a0 + a1 x + a2 x2 + . . . + an xn .
y0 = a0 + a1 x0 + a2 x02 + . . . + an x0n .
y1 = a0 + a1 x1 + a2 x12 + . . . + an x1n .
..
.
yn = a0 + a1 xn + a2 xn2 + . . . + an xnn .
1 x0 x02 . . . x0n
2 n
a0 y0
1 x1 x1 . . . x1 a1 y1
A = . .. , X =
. . . and b = . . .
..
.. . .
1 xn x 2 . . . x n an yn
n n
1 x0 x02 . . . x0n
1 x1 x12 . . . x1n
Y n
D= . = (xi − xj ) 6= 0
.. ..
..
. . i,j=0,
1 xn x 2 . . . x n i6=j
n n
I Therefore,
yi
Ai = .
Pi (xi )
I Hence,
n
X Pk (x)
Ln (x) = y = φ(x) = yk
Pk (xk )
k=0
n Y
n
X (x − xi )
= yk (1)
(xk − xi )
k=0 i=0
i6=k
Problem
Certain corresponding values of x and log10 x are
(300, 2.4771), (304, 2.4829), (305, 2.4843) and (307, 2.4871). Find
log10 301.
Solution.
(301 − 304)(301 − 305)(301 − 307)
log10 301 = (2.4771)
(300 − 304)(300 − 305)(300 − 307)
(301 − 300)(301 − 305)(301 − 307)
+ (2.4829)
(304 − 300)(304 − 305)(304 − 307)
(301 − 300)(301 − 304)(301 − 307)
+ (2.4843)
(305 − 300)(305 − 304)(305 − 307)
(301 − 300)(301 − 304)(301 − 305)
+ (2.4871)
(307 − 300)(307 − 304)(307 − 305)
= 1.2739 + 4.9658 − 4.4717 + 0.7106
= 2.4786.
Problem
For the given table of values of y = f(x), construct a Lagrange Polynomial of
degree 3 and hence find the value of y when x = 3.
x 0 1 2 4
y 1 3 9 81
Solution. We have
(x − 1)(x − 2)(x − 4) 1
l0 (x) = = − (x3 − 7x2 + 14x − 8)
(0 − 1)(0 − 2)(0 − 4) 8
(x − 0)(x − 2)(x − 4) 1
l1 (x) = = (x3 − 6x2 + 8x)
(1 − 0)(1 − 2)(1 − 4) 3
(x − 0)(x − 1)(x − 4) 1
l2 (x) = = − (x3 − 5x2 + 4x)
(2 − 0)(2 − 1)(2 − 4) 4
(x − 0)(x − 1)(x − 2) 1 3
l3 (x) = = (x − 3x2 + 2x)
(4 − 0)(4 − 1)(4 − 2) 24
So,
1 1
L3 (x) = − (x3 − 7x2 + 14x − 8)(1) + (x3 − 6x2 + 8x)(3)
8 3
1 1
− (x3 − 5x2 + 4x)(9) + (x3 − 3x2 + 2x)(81)
4 24
Now, L3 (3) = 31.
Dr. B.S.R.V. Prasad | MAT3005 - Applied Numerical Methods
Lagrange Interpolation
17
Problem
If y1 = 4, y3 = 12, y4 = 19 and yx = 17, find x.
Problem
√ √
From the given table of square-roots, calculate 151 and 155, by Lagrange
interpolation formula:
x√ 150 152 154 156
y= x 12.247 12.329 12.410 12.490
Problem
From the given table of values, calculate f(0.35) and f(0.65) by Lagrange
Interpolation formula
x 0.30 0.40 0.50
f(x) −1.203973 −0.916291 −0.693147
0.60 0.70
−0.510826 −0.356675
Few Observations
I The arguments xi , i = 0, 1, . . . , n, need not be equispaced points in a
table; i.e., it is valid and useful for unequal intervals.
I The degree n of the approximating polynomial should be small,
preferably 5 or 6 (not higher), otherwise the polynomials may give rise
to oscillations.
I If we want to add one more data point, we have to compute the
polynomial from the beginning. It does not use the polynomial already
computed. That is, yk+1 (x) does not use yk (x) which is already
available.
Pn (x) = a0 + a1 (x − x0 ) + a2 (x − x0 )(x − x1 )
+ . . . + an (x − x0 )(x − x1 ) . . . (x − xn−1 )
Pn (xk ) = yk , k = 0, 1, 2, . . . , (n − 1).
I Now, at x = x0 , we have
Pn (x0 ) = a0 = y0 .
I Similarly, at x = x1 , we have
Pn (x1 ) = a0 + a1 (x1 − x0 ) = y1 .
I Therefore,
y1 − y0
a1 = .
x1 − x0
Dr. B.S.R.V. Prasad | MAT3005 - Applied Numerical Methods
Newton’s Divided Difference Interpolation
24
y[xk ] = yk
y[xk+1 ] − y[xk ]
y[xk , xk+1 ] =
xk+1 − xk
y[xk+1 , xk+2 ] − y[xk , xk+1 ]
y[xk , xk+1 , xk+2 ] =
xk+2 − xk
y[xk+1 , . . . , xi+1 ] − y[xk , . . . , xi ]
y[xk , xk+1 , . . . , xi , xi+1 ] =
xi+1 − xk
I These quantities are called divided differences.
a0 = y0 = y[x0 ]
y1 − y0
a1 = = y[x0 , x1 ]
x1 − x0
y2 −y1
− yx11 −y 0
a2 = x2 −x1 −x0
x2 − x0
y[x1 , x2 ] − y[x0 , x1 ]
=
x2 − x0
= y[x0 , x1 , x2 ]
I Thus,
an = y[x0 , x1 , . . . , xn ].
n (i−1)
X Y
Pn (x) = y[x0 , x1 , . . . , xi ] (x − xj )
i=0 j=0
Problem
Given below is a table of data for log x. Estimate log 2.5 using second order
Newton interpolation polynomial.
i 0 1 2 3
xi 1 2 3 4
log xi 0 0.3010 0.4771 0.6021
Hint: Second order polynomial require only three data points. Use the first
three points and find a0 , a1 and a2 .
Splines
I So far we have discussed how an interpolation polynomial of degree n
can be constructed and used if a set of values of function are given.
I There are situations in which this approach is likely to face problems
and produced incorrect estimates.
I This is because the interpolation takes a global rather than a local view
of data.
I It has been proved that when n is large compared to the order of the
“true" function, the interpolation polynomial of degree n does not
provide accurate results at the end of the range.
I Thus, increasing the order of polynomials does not necessarily increase
the accuracy.
Splines
I To overcome this problem, one can divide the entire range into
subintervals and use local low-order polynomials to interpolate each
subinterval.
I These local polynomials are called piecewise polynomials, which are
continuous in the subinterval and discontinuous at the interpolating
points.
I We can construct piecewise polynomials such that they are continuous
at the interpolating points also.
I This type of polynomials are called Spline polynomials.
I The concept of splines originated from the mechanical drafting tool
called “spline" used by designers for drawing smooth curves.
I The connection points are called knots or nodes.
Definition
Spline function A spline function of degree n over the interval [x0 , xn ] with
knots (nodes) xi , i = 0, 1, 2, . . . , n is a function S(x) with the properties:
(i) si (x) is a polynomial of degree at most n in each of the subintervals
[xi−1 , xi ], 1 ≤ i ≤ n.
(ii) si (x) and its derivatives of orders 1, 2, . . . , n − 1 are continuous on
[x0 , xn ].
The set of all polynomials form a spline interpolating polynomial if
si (xi ) = f(xi ), for i = 0, 1, 2, . . . , n. The process of constructing such
polynomials for a given set of function points is known as spline
interpolation.
Definition
Cubic Splines A Cubic spline interpolating polynomial over the interval
[x0 , xn ] with knots (nodes) xi , i = 0, 1, 2, . . . , n is a function S(x) with the
properties:
(i) si (x) is almost a cubic in each of the subintervals [xi−1 , xi ], 1 ≤ i ≤ n.
(ii) si (xi ) = yi = f(xi ), i = 0, 1, 2, . . . , n.
(iii) si (x), s0i (x) and s00i (x) are continuous on [x0 , xn ], and
(iv) s00i (x0 ) = s00i (xn ) = 0.
To derive the governing equations of the cubic spline, we observe that the
spline second derivatives must be linear. Hence we have in [xi−1 , xi ]:
1
s00i (x) = [(xi − x)Mi−1 + (x − xi−1 )Mi ]
hi
Cubic Splines
The cubic spline interpolating polynomial si (x) in the interval [xi−1 , xi ] is
given by
1
si (x) = [(xi − x)3 Mi−1 + (x − xi−1 )3 Mi ]
6hi
h2
1
+ fi−1 − i Mi−1 (xi − x)
hi 6
h2i
1
+ fi − Mi (x − xi−1 )
hi 6
Cubic Splines
For equal intervals, hi = hi+1 = h and hence the above equations reduces
to:
1
si (x) = [(xi − x)3 Mi−1 + (x − xi−1 )3 Mi ]
6h
h2
1
+ fi−1 − Mi−1 (xi − x)
h 6
h2
1
+ fi − Mi (x − xi−1 ) (3)
h 6
and
6
Mi−1 + 4Mi + Mi+1 = (fi+1 − 2fi + fi−1 ) (4)
h2
(Here Mi = s00 (xi )).
Determining Mi ’s
Finally, we have a system of n − 1 linear equations in n + 1 unknowns
M0 , M1 , M2 , . . . , Mn . Therefore to solve this system, we require two
additive conditions, which may be taken in one of the following forms:
(i) M0 = Mn = 0 (A spline satisfying these conditions is called a natural
spline).
(ii) M0 = Mn , M1 = Mn+1 , f0 = fn+1 , h1 = hn+1 (A spline satisfying these
conditions is called a periodic spline).
(iii) For a non-periodic spline, we take the conditions:
s0i (a) = f 0 (a) = f00 ; s0i (b) = f 0 (b) = fn0
Problem
Obtain the cubic spline approximation for the function given in the tabular
form:
x 0 1 2 3
f(x) 1 2 33 244
and M0 = M3 = 0.
Case (ii):
Now in the interval [1, 2] we have i = 2, h = 1 and required cubic spline is:
1 1
s2 (x) = [(x2 − x)3 M1 + (x − x1 )3 M2 ] + 1 × (x2 − x) f1 − M1
6 6
1
+ 1 × (x − x1 ) f2 − M2
6
1 24
= [(2 − x) (−24) + (x − 1)3 (276)] + (2 − x) 2 +
3
6 6
276
+ (x − 1) 33 −
6
= 50x3 − 162x2 + 167x − 53.
Finally, in the interval [2, 3] we have i = 3, h = 1 and required cubic spline is:
1 1
s3 (x) = [(x3 − x)3 M2 + (x − x2 )3 M3 ] + 1 × (x3 − x) f2 − M2
6 6
1
+ 1 × (x − x2 ) f3 − M3
6
1 3 276
= [(3 − x) (276)] + (3 − x) 33 − + (x − 2)(244)
6 6
= −46x3 + 414x2 − 985x + 715.
Problem
Given the table of values
i 0 1 2 3
xi 1 2 3 4
f(x) 0.5 0.3333 0.25 0.20
estimate the value of f(2.5) and f(3.5) using cubic spline interpolation.
Case (ii):