Slide16 Interpolation
Slide16 Interpolation
Jadavpur University
φ(x) = a0 + a1 x + a2 x 2 + . . . + an x n
Linear Interpolation I
I Where,
b0 = f (x0 )
f (x1 ) − f (x0 )
b1 = (3)
x1 − x0
f (x2 ) − f (x1 ) f (x1 ) − f (x0 )
−
x2 − x1 x1 − x0
b2 =
x2 − x0
I Exercise: Estimate the value of ln 2 Using a second order
polynomial and the given three points
Quadratic Interpolation II
x x0 = 1 x1 = 4 x2 = 6
f (x) = ln x f (x0 ) = 0 f (x1 ) = 1.386294 f (x2 ) = 1.791759
I Solution: Using equation 3, we get
I b0 = f (x0 ) = f (1) = 0
b1 = f (xx11)−f
−x0
(x0 )
= f (4)−f
4−1
(1)
= 1.386294−0
3 = 0.4620981
f (x2 )−f (x1 ) f (x )−f (x ) f (6)−f (4) f (4)−f (1)
x2 −x1 − x1 −x 0 6−4 − 4−1
b2 = x2 −x0
1 0
= 6−1 =
1.791759−1.386294
− 1.386294−0
2
5 = −0.0518731
3
fn (x) = b0 + b1 (x − x0 ) + b2 (x − x0 )(x − x1 ) + . . .
+ bn (x − x0 )(x − x1 ) . . . (x − xn−1 )
where,
(∆dn−1 f1 − ∆dn−1 f0 )
∆nd f0 =
(xn − x0 )
I Exercise: Estimate the value of ln 2 Using a third order
polynomial and the given four points
x x0 = 1 x1 = 4 x2 = 5 x3 = 6
f (x) = ln x 0 1.386294 1.609438 1.791759
I Solution: Divided difference table for the given four data
points
General Form of Newton’s Interpolating Polynomial V
x f (x) ∆d f ∆2d f ∆3d f
x0 = 1 0
0.462098
x1 = 4 1.386294 −0.0597385
0.223144 0.0078654
x2 = 5 1.609438 −0.0204115
0.182321
x3 = 6 1.791759
I General form of Newton’s divided difference third order
formula is
f (x) = f (x0 )+∆d f0 (x −x0 )+∆2d f0 (x −x0 )(x −x1 )+∆3d f0 (x −x0 )(x −x1 )(x −x2 )
I Putting x = 2, we get
f (2) = 0.462098(2−1)−0.0597385(2−1)(2−4)+0.0078654(2−1)(2−4)(2−5) =
0.462098 + 0.119477 + 0.0471924 = 0.6287674
0.6931472−0.6287674
I Percentage error εp = 0.6931472 × 100% = 9.29%
General Form of Newton’s Interpolating Polynomial VII
Algorithm 1 Algorithm for Newton’s Divided Difference Interpolat-
ing Polynomial
Input: Array x and y contains n + 1 numbers of x and f (x) values respectively, xi is
the point where the value of the function f has to be interpolated
Output: The value of f (xi)
1: /*fdd is an (n + 1) × (n + 1) array which stores the finite divided differences*/
2: for i = 0 to n in steps of 1 do
fdd[i][0] = y [i]
3: end for
4: /*computation of finite divided differences*/
5: for j = 1 to n in steps of 1 do
6: for i = 0 to n − j in steps of 1 do
fdd[i][j] = (fdd[i + 1][j − 1] − fdd[i][j − 1])/(x[i + j] − x[i])
7: end for
8: end for
9: /*computation of the value of the function at the point xi */
10: xterm = 1
11: yint[0] = fdd[0][0]
12: for order = 1 to n in steps of 1 do
13: xterm = xterm ∗ (xi − x[order − 1])
14: yint[order ] = yint[order − 1] + fdd[0][order ] ∗ xterm
15: end for
Lagrange Interpolation I
I Evaluation of polynomial coefficients become simpler when
the following form is considered
f (x) = c0 (x − x1 )(x − x2 ) . . . (x − xn )
+ c1 (x − x0 )(x − x2 ) . . . (x − xn )
...
+ cn (x − x0 )(x − x1 ) . . . (x − xn−1 )
where,
f (x0 )
c0 =
(x0 − x1 )(x0 − x2 ) . . . (x0 − xn )
f (x1 )
c1 =
(x1 − x0 )(x1 − x2 ) . . . (x1 − xn )
..
.
f (xn )
cn =
(xn − x0 )(xn − x1 ) . . . (xn − xn−1 )
Lagrange Interpolation II
x x0 = 1 x1 = 4 x2 = 6
f (x) = ln x f (x0 ) = 0 f (x1 ) = 1.386294 f (x2 ) = 1.791759
I Solution:
I The first order Lagrange polynomial
x − x1 x − x0
f1 (x) = f (x0 ) + f (x1 )
x0 − x1 x1 − x0
x −4 x −1
=0× + 1.386294 ×
1−4 4−1
2−1
f1 (2) = 1.386294 × = 0.462098
4−1
Lagrange Interpolation V
(2 − 1)(2 − 6) (2 − 1)(2 − 4)
f2 (2) = 1.386294 × + 1.791759 ×
(4 − 1)(4 − 6) (6 − 1)(6 − 4)
2 1
= 1.386294 × − 1.791759 × = 0.924196 − 0.3583518 = 0.5658442
3 5
Differences of a Polynomial I
I Let f (x) be a polynomial of nth degree
f (x) = a0 + a1 x + a2 x 2 + . . . + an x n
I Then we obtain
f (x+h)−f (x) = a1 [x+h−x]+a2 [(x+h)2 −x 2 ]+. . .+an [(x+h)n −x n ]
or
f = f (x + h) − f (x) = a1 h + a20 x + . . . + an−1
0
x n−1
I This is a polynomial of order (n − 1)
I By repeated application we get
I ∆2 f is a polynomial of degree (n − 2)
I ∆3 f is a polynomial of degree (n − 3)
......
I ∆n f is a constant
I Thus by inspecting the difference table we can decide the
order of the polynomial to be chosen
Newton’s Forward Difference Formula I
∆ 2 f0
f (x0 + uh) = f (x0 ) + ∆f0 u + u(u − 1)
2!
∆ n f0
+ ... + u(u − 1)(u − 2) . . . (u − n − 1)
n!
I This is known as Newton Gregory Forward Interpolation
Formula
I In general, Newton’s forward difference formula is used to
compute the approximate value of f (x) when the value of x is
near to x0 of the given table. But, if the value of x is at the
end of the table, then this formula gives more error. In this
case, Newton’s backward formula is used.
Newton’s Forward Difference Formula V
x 0 1 2 3 4
f (x) 1 7 23 55 109
x f (x) ∆f ∆2 f ∆3 f ∆4 f
0 1
6
1 7 10
16 6
2 23 16 0
32 6
3 55 22
54
4 109
Table 2: Forward Difference Table
Newton’s Forward Difference Formula VII
∆2 f0 ∆ 3 f0
f (x0 + uh) = f (x0 ) + ∆f0 u + u(u − 1) + u(u − 1)(u − 2)
2! 3!
I Backward Differences
I ∇: backward difference operator
I First backward difference: differences in f (x) values
I ∇fn = f (xn ) − f (xn−1 ), ∇fn−1 = f (xn−1 ) − f (xn−2 ), . . . , ∇f2 =
f (x2 ) − f (x1 ), ∇f1 = f (x1 ) − f (x0 )
I Second backward difference: differences in first backward
differences
I ∇2 fn = ∇fn − ∇fn−1 , ∇2 fn−1 = ∇fn−1 − ∇fn−2 , . . . , ∇2 f3 =
∇f3 − ∇f2 , ∇2 f2 = ∇f2 − ∇f1
I Similarly we can define third backward difference, fourth
backward difference etc.
Newton’s Backward Difference Formula II
x f (x) ∇ ∇2 ∇3 ∇4 ∇5
x0 f (x0 )
∇f1
x1 f (x1 ) ∇2 f2
∇f2 ∇ f3
x2 f (x2 ) ∇2 f3 ∇4 f4
∇f3 ∇3 f4 ∇5 f5
x3 f (x3 ) ∇2 f4 ∇4 f5
∇f4 ∇3 f5
x4 f (x4 ) ∇2 f5
∇f5
x5 f (x5 )
Table 3: Backward Difference Table
Newton’s Backward Difference Formula III
∇fn ∇ 2 fn
fn (x) = f (xn ) + (x − xn ) + (x − xn )(x − xn−1 ) + . . .
h 2!h2
n
∇ fn
+ (x − xn )(x − xn−1 ) . . . (x − x1 )
n!hn
I This polynomial can be expressed more concisely by
considering x = xn + uh, so
I x − xn = uh
I x − xn−1 = (xn + uh) − (xn − h) = h(u + 1)
I x − xn−2 = x − (xn−1 − h) = h(u + 1) + h = h(u + 2)
......
I x − x1 = h(u + n − 1)
I Substituting above into the polynomial we get
u(u + 1) 2
fn (x) = f (xn ) + u∇fn + ∇ fn + . . .
2!
∇ n fn
+ u(u + 1) . . . (u + n − 1)
n!
Newton’s Backward Difference Formula V
x f (x) ∇f ∇2 f ∇3 f ∇4 f
1971 46
20
1981 66 -5
15 2
1991 81 -3 -3
12 -1
2001 93 -4
8
2011 101
Table 4: Backward Difference Table
Newton’s Backward Difference Formula VII
Newton’s backward difference formula for a degree four
polynomial is
−0.6(−0.6 + 1)
f (2005) = 101 + −0.6 × 8 + × −4
2
−0.6(−0.6 + 1)(−0.6 + 2)
+ × −1
6
−0.6(−0.6 + 1)(−0.6 + 2)(−0.6 + 3)
+ × −3
24
= 101 − 4.8 + 0.48 + 0.056 + 0.1008 = 96.8368