You are on page 1of 14

Chapter 3

Interpolation

Dr. Gokul K. C.
Department of Mathematics,
School of Science,
Kathmandu University, Nepal
Email: gokul.kc@ku.edu.np

Numerical Methods (MCSC 202)

1 / 30
Curve fitting and Interpolation
Given the set of tabular values (x0 , y0 ), (x1 , y1 ), (x2 , y2 ), · · · , (xn , yn ) satisfying
the relation y = f (x) where the explicit nature of f (x) is not known, it is
required to find a simpler function, say φ(x).
Curve fitting is the process of approximating φ(x) that approximately fits
the data points, while, Interpolation is the process of approximating φ(x)
such that f (x) and φ(x) agree at the set of tabulated points.
The curve is not necessarily passing through data points in curve fitting,
however, the curve must pass though every data points in interpolation.

2 / 30
Least square curve fitting procedure
Let the fitted curve is given by Y = f (x). At x = xi , the given ordinate is yi
and the corresponding functional value of the fitted curve is f (xi ). If ei is
the error of approximation at x = xi , then we have, ei = yi − f (xi ).
If we write
S = [y1 − f (x1 )]2 + [y2 − f (x2 )]2 + · · · + [ym − f (xm )]2 = e12 + e22 + e32 + · · · + em2

then the method of least squares consists in minimizing S.


Fitting a straight line
If Y = a + bx be straight line fitted to the points (xi , yi ), then
S = [y1 − (a + bx1 )]2 + [y2 − (a + bx2 )]2 + · · · + [ym − (a + bxm )]2
For S to be minimum, we have
∂S
∂a = 0 = −2[y1 − (a + bx1 )] − 2[y2 − (a + bx2 )] − · · · − 2[ym − (a + bxm )]
=⇒ ma + b(x P1m+ x2 + ·P · · + xm ) = y1 + y2 + · · · + ym
m
=⇒ ma + b i=1 xi = i=1 yi · · · (1)
Similarly,
∂S
∂b = 0 = −2x1 [y1 − (a + bx1 )] − 2x2 [y2 − (a + bx2 )] − · · · − 2xm [ym − (a + bxm )]
2 2 2
=⇒ a(xP 1 + x2 + · · ·P+ xm ) + b(xP1m+ x2 + · · · + xm ) = x1 y1 + x2 y2 + · · · + xm ym
m m 2
=⇒ a i=1 xi + b i=1 xi = i=1 xi yi · · · (2)
Equations (1) and (2) are called normal equations. Solving these for a and
b and substituting in the equation Y = a + bx, we get the required fitted
straight line. 3 / 30
Example
Fitting exponential functions:
Fit a straight line from the data
given (0, −1), (2, 5), (5, 12), (7, 20)
y = ab x , y = ax b and y = ae bx
Given: y = ax b
Solution: Let Y = a + bx be re- Taking log on both sides
quired fitted straight line. The ta- logy = log (ax b )
ble of values are logy = loga + logx b
x y x 2 xy logy = loga + blogx
0 −1 0 0 Y = A + bX , Which is a straight
2 5 4 10 line. Where, Y = logy , A = loga and
5 12 25 60 X = logx.
7 20 49 140 After calculation of A, we have
14 36 78 210 a = e A.
The normal equations are:
4a + 14b = 36 Fit a function of the form y = ax b
14a + 78b = 210 for the following data:
Solving, we get, a = −1.1381 and x 61 26 7 2.6
b = 2.8966 y 350 400 500 600
∴ Y = −1.1381 + 2.8966x

4 / 30
Fitting qudratic polynomial

Let the quadratic polynomial is given by:


y = a + bx + cx 2
P P P 2
For normal equations, we take , x and x on both sides
P
Taking on both sides, we get
a + bx + cx 2 =⇒ y = na + b x + c x 2
P P P P P P P
y=
P
Taking x on both sides, we get
xa + bx 2 + cx 3 =⇒ xy = a x + b x 2 + c x 3
P P P P P P P P
xy =
P 2
Taking x on both sides, we get
P 2 P 2
x a + bx 3 + cx 4 =⇒
P 2
x y = a x2 + b x3 + c x4
P P P P P
x y=

Fit a second degree parabola y = a + bx + cx 2 to the data:


(1, 0.63), (3, 2.05), (4, 4.08), (6, 10.78)

5 / 30
Interpolation
Finite Differences
Let y0 and y1 be two data points and y1 − y0 be difference such that:
First forward difference: ∆y0 = y1 − y0
First backward difference: ∇y1 = y1 − y0
First central difference: δy1/2 = y1 − y0

The difference y1 − y0 is same but representation is different.

6 / 30
Forward differences
∆y0 = y1 − y0 , ∆y1 = y2 − y1 , · · · , ∆yn−1 = yn − yn−1 are called first forward
differences.
∆2 y0 = ∆y1 − ∆y0 , ∆2 y1 = ∆y2 − ∆y1 , · · · , ∆2 yn−1 = ∆yn − ∆yn−1 are called
second order differences and so on.

7 / 30
Backward differences
∇y1 = y1 − y0 , ∇y2 = y2 − y1 , · · · , ∇yn = yn − yn−1 are called first forward
differences.
∇2 y2 = ∇y2 − ∇y1 , ∇2 y3 = ∇y3 − ∇y2 , · · · , ∇2 yn = ∇yn − ∇yn−1 are called
second order differences and so on.

8 / 30
Newton’s backward difference interpolation formula
Given the set of (n + 1) tabular values (x0 , y0 ), (x1 , y1 ), (x2 , y2 ), · · · , (xn , yn ) of
x and y , it is required to find a polynomial yn (x), such that y and yn (x)
agree at the tabulated points. Let the domain values are in equidistant, i.e,
xi = x0 + ih, i = 0, 1, 2, · · · , n.
Let the polynomial yn (x) be written as (Starting from backward points)
yn (x) = a0 +a1 (x −xn )+a2 (x −xn )(x −xn−1 )+a3 (x −xn )(x −xn−1 )(x −xn−2 )+· · ·
+an (x − xn )(x − xn−1 )(x − xn−2 ) · · · (x − x1 )
Substituting the data values (Starting from last data) successively, we get
(xn , yn ) : yn = a0 → a0 = yn
(xn−1 , yn−1 ) : yn−1 = a0 + a1 (xn−1 − xn ) =⇒ yn−1 = yn + a1 (−h)
−yn
=⇒ a1 = yn−1 −h = ∇y h
n

(xn−2 , yn−2 ) : yn−2 = a0 + a1 (xn−2 − xn ) + a2 (xn−2 − xn )(xn−2 − xn−1 )


=⇒ yn−2 = a0 + a1 (−2h) + a2 (−2h)(−h)
=⇒ yn−2 = yn + ∇y h (−2h) + a2 2h
n 2

=⇒ yn−2 = yn + (yn − yn−1 )(−2) + a2 2h2


=⇒ yn−2 − yn = −2yn + 2yn−1 + a2 2h2
=⇒ yn−2 − 2yn−1 + yn = a2 2h2
=⇒ ∇2 yn = a2 2h2
2
∇2 yn ∇n yn
=⇒ a2 = ∇2hy2n = 2! h2 , · · · , an = n! hn
9 / 30
Substituting these values in polynomial yn (x), we get
∇2 yn 3
yn (x) = yn +(x −xn ) ∇yh +(x −xn )(x −xn−1 ) 2!h2 +(x −xn )(x
n
−xn−1 )(x −xn−2 ) ∇3!hy3n
n
+ · · · + (x − xn )(x − xn−1 )(x − xn−2 ) · · · (x − x1 ) ∇ yn
n!hn

Setting x = xn + ph we have,
x − xn = (xn + ph) − xn = ph
x − xn−1 = (xn + ph) − xn−1 = ph + xn − xn−1 = ph + h = h(p + 1)
x − xn−2 = (xn + ph) − xn−2 = ph + xn − xn−2 = ph + 2h = h(p + 2)
..
.
x − x1 = (xn + ph) − x1 = ph + xn − x1 = ph + xn − x0 + x0 − x1
= ph + nh − h = h(p + n − 1)
Substituting these values, we get
∇2 y n 3
yn (x) = yn + (ph) ∇yh + (ph)[h(p + 1)] 2!h2 + (ph)[h(p + 1)][h(p
n
+ 2)] ∇3!hy3n
n
+ · · · + (ph)[h(p + 1)][h(p + 2)] · · · [h(p + n − 1)] ∇ yn
n!hn

Therefore the final formula is 2


∇3 yn
yn (x) = yn + p ∇y ∇ yn
1! + p(p + 1) 2! + p(p + 1)(p n+ 2) 3!
n

+ · · · + p(p + 1)(p + 2) · · · (p + n − 1) ∇n!yn

10 / 30
11 / 30
Central difference formulas

Gauss Forward Formula:


yp = y0 + p∆y0 + p(p−1) 2
2! ∆ y−1 +
(p+1)p(p−1) 3
3! ∆ y−1 + (p+1)p(p−1)(p−2)
4! ∆4 y−2 + · · ·
Gauss Backward Formula:
yp = y0 + p∆y−1 + p(p+1) 2
2! ∆ y−1 +
(p+1)p(p−1) 3
3! ∆ y−2 + (p+2)(p+1)p(p−1)
4! ∆4 y−2 + · · ·
Stirling’s Formula:
2 2 3 3 2 2
yp = y0 + p ∆y−12+∆y0 + p2! ∆2 y−1 + p(p3!−1) ∆ y−1 +∆
2
y−2
+ p (p4!−1) ∆4 y−2 + · · ·
∆2 y−1 +∆2 y0
Bessel’s Formula:yp = y0 +y1
2 + (p − 1/2)∆y0 + p(p−1)
2! 2 +
4 4
p(p−1)(p−1/2) 3 (p+1)p(p−1)(p−2) ∆ y−2 +∆ y−1
3! ∆ y−1 + 4! 2 + · · ·
12 / 30
Estimate the values of f (x) at x = 0.98, 1.02, 1.12, 1.16, 1.27, 1.34 from the
given data values: (1.00, 2.7183), (1.05, 2.8577), (1.10, 3.0042), (1.15, 3.1582),
(1.20, 3.3201), (1.25, 3.4903), (1.30, 3.6693).

Given: h = 0.05, x0 = 1.00, x = 0.98


=⇒ p = 0.98−1.00
0.05 = −0.4
Newton’s forward formula: yn (x) =
∆2 y 0 ∆3 y0
y0 +p ∆y
1! +p(p−1) 2! +p(p−1)(p−2) 3! .
0

= 2.7183 + (−0.4)(0.1394) +
(−0.4)(−1.4)
2 (0.0071) +
(−0.4)(−1.4)(−2.4)
6 (0.0004)
= 2.6644
Now, for x = 1.02, p = 1.02−1 0.05 = 0.4.
Then, yn = 2.77.

For x = 1.27, we have, h = 0.05, xn = 1.30 =⇒ p = 1.27−1.300.05 = −0.6


Newton’s backward formula: 2
∇3 yn
yn (x) = yn + p ∇y ∇ yn
1! + p(p + 1) 2! + p(p + 1)(p + 2) 3! .
n

= 3.6693 + (−0.6)(0.1790) + (−0.6)(0.4)


2 (0.0088) + (−0.6)(0.4)(1.4)
6 (0.0005)
= 3.561
Now, for x = 1.34, p = 1.34−1
0.05 = 0.8. Then, yn = 3.6726. 13 / 30
Given: h = 0.05, x0 = 1.15, x = 1.12
=⇒ p = 1.12−1.15
0.05 = −0.6
Stirling’s formula: yp = y0 + p ∆y−12+∆y0 +
p2 2 p(p 2 −1) ∆3 y−1 +∆3 y−2
2! ∆ y−1 + 3! 2 +
p 2 (p 2 −1) 4
4! ∆ y −2 = 3.1582 +
90.1540+0.1619) (−0.6)2
(−0.6)( 2 + 2 (0.0079) +
(−0.6)((−0.6)2 −1) 0.0004+0.0004)
6 ( 2 )
= 3.065
1.16−1.15
Now, for x = 1.16, p = 0.05 = 0.2.
Then, yn = 3.19.
For x = 1.12, we have, h = 0.05, x0 = 1.10 =⇒ p = 1.12−1.10 0.05 = 0.4
Bessel’s formula:
∆2 y−1 +∆2 y0
yp = y0 +y
2
1
+ (p − 1/2)∆y0 + p(p−1)
2! 2 + p(p−1)(p−1/2)
3! ∆3 y−1 =
(3.0042+3.1582) (0.4)(−0.6) (0.0075+0.0079) (0.4)(−0.6)(−0.1)
2 + (−0.1)(0.1540) + 2 2 + 6 (0.0004)
= 3.065
Now, for x = 1.16, p = 1.16−1.15
0.05 = 0.2. Then, yn = 3.19.

14 / 30

You might also like