Lagrange Interpolation
Lagrange Interpolation
If x0, x1, . . . , xn are arbitrarily spaced (i.e. if the difference between x0 and x1, x1 and x2
etc. may not be equal), then the polynomial of degree n through ( x0 , f 0 ), ( x1 , f1 ), , ( xn , f n ),
where f j f ( x j ), is given by the Newton’s divided difference interpolation formula (also
known as Newton’s general interpolation formula) given by
f x f 0 x x 0 f x 0 , x1 x x 0 x x1 f x 0 , x1 , x 2 . . .
x x0 . . . x xn 1 f x0 , . . . , xn ,
( x x0 ) ( x x1 ) ( x xn ) f [ x, x0 , x1 , xn ]
f x1 f x0
f x0 , x1 ,
x1 x0
f x1 , x2 f x0 , x1
f x0 , x1 , x2 ,
x2 x0
f x1 , . . . , x k f x0 , . . . , x k 1
f x0 , . . . , x k
x k x0
f [ x p x1 , , xn ] f ( x, x0 ,] xn
Also, f [ x, x0 , x1 , , xn ]
x0 x
k f 0
Note If x0, x1, . . . , xn are equally spaced, i.e. when xk x0 kh, then f x 0 , . . . , x k
k ! hk
and Newton’s divided difference interpolation formula takes the form of Newton’s
forward difference interpolation formula.
f xi 1 f xi
f xi , xi 1 for i 0,1,..., n 1
xi 1 xi
f xi 1 , xi 2 f xi , xi 1
f xi , xi 1 , xi 2 for i 0,1,..., n 2
xi 2 xi
In general the nth divided difference (or divided difference of order n) between
x1 , x2 ,..., xn is,
f x1 , x2 ,..., xn f x0 , x1 ,..., xn 1
f x0 , x1 ,..., xn
xn x0
f x1 f x0
f x0 , x1
x1 x0
f x1 , x2 f x0 , x1
f x0 , x1 , x2
x2 x0
1 f x2 f x1 f x1 f x0
x2 x0 x2 x1 x1 x0
f x2 f x1 1 1 f x0
x2 x0 x2 x1 x2 x0 x2 x1 x1 x0 x2 x0 x1 x0
f x2 f x1 f x0
x2 x0 x2 x1 x2 x1 x1 x0 x2 x0 x1 x0
f x0 f x1 f x2
f x0 , x1 , x2
x0 x2 x0 x1 x1 x0 x1 x2 x2 x0 x2 x1
As above, the nth divided difference between x1 , x2 ,..., xn , f x0 , x1 ,..., xn is expressed
as
f x0 f x1
f x0 , x1 ,..., xn ...
0 1 0 2 0 n 1 0 1 x2 ... x1 xn
x x x x ... x x x x x
f xn
n 0 n x1 ... xn xn 1
x x x
f x1 f x0
We have, f x0 , x1
x1 x0
f x0 f x1
f x1 , x0
x0 x1
When we are considering the nth divided difference also, we can write, f x0 , x1 ,..., xn as
f x0 f x1 f xn
f x0 , x1 ,..., xn ...
x0 x1 x0 x2 ... x0 xn x1 x0 x1 x2 ... x1 xn xn x0 xn x1 ... xn xn1
From this expression it is clear that, whatever be the order of the arguments, the expression is
same.
h( x) af x b g ( x) ,
where ‘a’ and ‘b’ are any two real constants. The first divided difference of h( x) corresponding to
the arguments x0 and x1 is,
h x1 h x0 af x1 b g ( x1 ) af x0 b g ( x0 )
h x0 , x1
x1 x0 x1 x0
a f x1 f x0 b g ( x1 ) g ( x0 )
x1 x0
f x1 f x0 g ( x1 ) g ( x0 )
a b
x1 x0 x1 x0
a f x0 , x1 bg x0 , x1
f x1 f x0 x1n x0 n
Now, f x0 , x1
x1 x0 x1 x0
f x1 , x2 f x0 , x1
f x0 , x1 , x2
x2 x0
x 2
n 1
x2 n 2 x1 ... x1n 1 x0 n 1 x0 n 2 x1 ... x1n 1
, which
x2 x0
can be expressed as a polynomial of degree n-2, is symmetric about x0 , x1 and x2 with
leading coefficient 1.
g x a0 x n a1 x n 1 a2 x n 2 ... an
Since the divided difference operator is linear, we get nth divided difference of g x as a0 , which is
the leading coefficient of g x .
x f ( x)
1 3
0 6
3 39
6 822
7 1611
x f ( x) f [ xk , xk 1 ]
1 3
9
0 6 6
15 5
3 39 41 1
261 13
6 822 132
789
7 1611
Hence
f ( x ) 3 ( x 1) (9) x ( x 1) (6) x ( x 1) ( x 3)(5)
x ( x 1) ( x 3)( x 6)
x 4 3 x 3 5 x 2 6.
Example Find the interpolating polynomial by Newton’s divided difference formula for
the following table and then calculate f(2.1).
x 0 1 2 4
f(x) 1 1 2 5
First Second
Third divided
divided divided
x f(x) difference
difference difference
f[xk -1, xk, xk+1, xk+2]
f[xk -1, xk] f[xk -1, xk, xk+1]
f ( x0 , x1 ) 0
0 1
f ( x1 , x2 ) 1
1 1 1/ 2 1
f ( x2 , x3 ) 3/ 2 2
2 2 1/ 6
4 5
1 x 3 x 2 x 1
3 2
12 4 3
7
NEWTON’ S AND LAGRANGIAN FORMULAE - PART II
f (x) f x0 x x0 f x0 , x1 x x0 x x1 f x0 , x1, x2
x x0 x x1 x x2 f x0 , x1, x2 , x3 ....
x x0 x x1 ..... x xn1 f x0 , x1,..., xn
Here x values are gives as, -4, -1, 0, 2 and 9. Corresponding f(x) values are
1245,33,5,9 and 1335.
On simplification, we get,
Consider two arguments x and x0 . The first divided difference between x and x0 is,
f x0 f x f x f x0
f x, x0
x0 x x x0
f x f x0 x x0 f x, x0 ---- (1)
f x0 , x1 f x, x0 f x, x0 f x0 , x1
f x, x0 , x1
x1 x x x1
f x, x0 f x0, x1 x x1 f x, x0, x1
f x f x0 x x0 f x0 , x1 x x1 f x, x0 , x1
That is,
f x f x0 x x0 f x0 , x1 x x0 x x1 f x, x0 , x1 --- (2)
f x, x0 , x1 f x0 , x1, x2 f x0 , x1, x2 f x, x0 , x1
f x, x0 , x1, x2
x2 x x x2
f x f x0 x x0 f x0, x1 x x0 x x1 x x2 f x, x0, x1, x2 f x0, x1, x2
f x0 x x0 f x0 , x1 x x0 x x1 f x0 , x1, x2 x x0 x x1 x x2 f x, x0 , x1, x2
f ( x) f x0 x x0 f x0 , x1 x x0 x x1 f x0 , x1 , x2
x x0 x x1 x x2 f x0 , x1 , x2 , x3 ....
x x0 x x1 ..... x xn f x, x0 , x1,..., xn
If f(x) is a polynomial of degree n, then f x, x0 , x1 ,..., xn 0 , because it is the (n+1)th
difference.
Hence we get,
f ( x) f x0 x x0 f x0 , x1 x x0 x x1 f x0 , x1 , x2
x x0 x x1 x x2 f x0 , x1 , x2 , x3 ....
x x0 x x1 ..... x xn1 f x0 , x1,..., xn
This is known as Newton’s interpolation formula with divided difference.
Note:
1. For the given arguments x1 , x2 ,..., xn , if all the kth , (k<n) divided differences are equal,
the k+1th divided differences are zeroes. Then Newton’s interpolation formula gives a
polynomial of degree k for the given data.
Problem 2: The following table gives the relation between steam pressure and
temperature. Find the pressure at temperature 3750.
Solution:
The given x values are 3610, 3670, 3780, 3870 and 3990. Corresponding f(x) values
are 154.9, 167.9, 191,212.5 and 244.2.
f ( x) f x0 x x0 f x0 , x1 x x0 x x1 f x0 , x1 , x2
x x0 x x1 x x2 f x0 , x1 , x2 , x3 ....
x x0 x x1 ..... x xn f x, x0 , x1,..., xn
Given f x0 f (3610 ) 154.9 . The divided differences for the given points are as
shown in the table.
X First divided Second divided Third Fourth
differences differences divided divided
differences differences
361
2.01666
367 0.00971
2.18181 0.0000246
378 0.01035 0.00000074
2.38888 0.0000528
387 0.01204
2.64166
399
Hence,
Also find f(4.5), f(8) and the second derivative of f(x) at x=3.2.
Solution:
Since the fourth divided differences are zeroes, f(x) is of degree 3 and it is obtained as,
f (x) f x0 x x0 f x0 , x1 x x0 x x1 f x0 , x1, x2
x x0 x x1 x x2 f x0 , x1, x2 , x3
That is,
f ( x) x 3 x 1
Lagrangian Interpolation
Another method of interpolation in the case of arbitrarily spaced pivotal values x0, x1, . . .
, xn is Lagrangian interpolation. This method is based on Lagrange’s n+1 point
interpolation formula given by
n
l x
f x Ln x lkkxk fk ,
k0
where
l0 ( x ) ( x x1 )( x x2 ) . . . . ( x xn ) ,
lk ( x) ( x x 0 ) ( x xk 1 )( x xk 1 ) ( x xn ) , 0 < k < n.
ln ( x ) ( x x0 )( x x1 ) . . ..( x xn 1 )
Remark: Lk ( xk ) f k . For, lk ( x j ) 0, when j k , so that for x xk , the sum on the RHS of the
formula reduces to the single term f k , which indicates that f and Lk agrees at n+1
tabulated points.
Since the interpolating polynomial must use all the ordinates f x0 , f x1 ,..., f xn , it can be
written as a linear combination of these ordinates. That is, we can write the polynomial as
pn ( x) l0 ( x) f x0 l1 ( x) f x1 ln ( x) f xn .
f ( x0 ) pn ( x0 ) l0 ( x0 ) f x0 l1 ( x0 ) f x1 ... ln ( x0 ) f xn
f ( xi ) pn ( xi ) l0 ( xi ) f x0 l1 ( xi ) f x1 ... ln ( xi ) f xn
li ( xi ) 1 C xi x0 xi x1 ... xi xi 1 xi xi 1 ... xi xn
1
Hence, C
xi x0 xi x1 ... xi xi 1 xi xi 1 ... xi xn
Therefore,
li ( x)
x x0 x x1 ... x xi 1 x xi 1 ... x xn
xi x0 xi x1 ... xi xi 1 xi xi 1 ... xi xn
Now the polynomial
pn ( x) l0 ( x) f x0 l1 ( x) f x1 ... ln ( x) f xn ,
with li ( x)
x x0 x x1 ... x xi 1 x xi 1 ... x xn is called Lagrange interpolating
xi x0 xi x1 ... xi xi 1 xi xi 1 ... xi xn
polynomial and li ( x ) are called Lagrange fundamental polynomials.
p1 ( x) l0 ( x) f x0 l1 ( x) f x1 , where, l0 ( x)
x x1 and l1 ( x)
x x0 .
x0 x1 x1 x0
Let x , f x , x , f x , x , f x
0 0 1 1 2 2 are the given three points. Then the Lagrange
polynomial of degree two for the data is given by
p2 ( x) l0 ( x) f x0 l1 ( x) f x1 l2 ( x) f x2 , where,
l0 ( x )
x x1 x x2 , l1 ( x)
x x0 x x2 and l2 ( x )
x x0 x x1 .
x0 x1 x0 x2 x1 x0 x1 x2 x2 x0 x2 x1
For the four points x0 , f x0 , x1 , f x1 , x2 , f x2 , x3 , f x3 , the Lagrange polynomial of
degree three is given by,
p3 ( x) l0 ( x) f x0 l1 ( x) f x1 l2 ( x) f x2 l3 ( x) f x3 , where, l0 ( x)
x x1 x x2 x x3
x0 x1 x0 x2 x0 x3
l1 ( x)
x x0 x x2 x x3 , l2 ( x )
x x0 x x1 x x3 and
x1 x0 x1 x2 x1 x3 x2 x0 x2 x1 x2 x3
l3 ( x)
x x0 x x1 x x2 and so on.
x3 x0 x3 x1 x3 x2
Problem : Given f(2) = 9, and f(6) = 17. Find an approximate value for f(5) by the method of
Lagrange’s interpolation.
Solution:
For the given two points (2,9) and (6,17), the Lagrangian polynomial of degree 1 is
p1 ( x) l0 ( x) f x0 l1 ( x) f x1 , where, l0 ( x)
x x1 and l1 ( x)
x x0 . That is,
x0 x1 x1 x0
x x1 f x x x0 f x
p1 ( x)
x0 x1 0 x1 x0 1
p1 ( x)
x 6 9 x 2 17
2 6 6 2
Hence,
f (5) P1 (5)
5 6 9 5 2 17
2 6 6 2
1 3
9 17
4 4
15
Problem: Use Lagrange’s formula, to find the quadratic polynomial that takes the values
x : 0 1 3
f ( x) : 0 1 0
For the given three points (0,0) , (1,1) and (3,0), the quadratic polynomial by Lagrange’s
x x1 x x2 f x x x0 x x2 f x x x0 x x1 f x
interpolation is p2 ( x)
x0 x1 x0 x2 0 x1 x0 x1 x2 1 x2 x0 x2 x1 2
We are considering the given x values 0,1, and 3 as x0 , x1 and x2 . Given, f x0 and f ( x2 )
are zeroes. Hence the polynomial is,
x x0 x x2 f x
p2 ( x )
x1 x0 x1 x2 1
Then,
p2 ( x )
x 0 x 3 1
1 0 1 3
x x 3
1 3x x 2 .
1
p2 ( x)
2 2
Example Find Lagrange’s interpolation polynomial fitting the points f(1) = 3, f(3) = 0,
f(4) = 30, f(6) = 132. Hence find f(5).
Here 4 tabulated points are given. Hence we need Lagrange’s polynomial for (n + = 3
+ 1 = 4 points) and is given by
l (x) 3
f (x) L3(x) k f
l (x ) k .
k0 k k
1 ( x 27 x 92 x 60), on simplification.
3 2
2
Now f (5) L3 (5) 1 (5) 27(5) 92(5) 60 75.
3 2
Example Find ln 9.2 with n 3 , using Lagrange’s interpolation formula with the given
table:
22 29 59 90
3 l (9.2)
ln(9.2) f (9.2) L3 9.2 k f .
l (x ) k
k 0 k k
2.4786.
where x0 1, y0 k , x y 3, y1 12 x2 4, y2 19 and y 7
(7 y1 ) (7 y2 ) (7 y0 ) (7 y2 )
i.e., x x0
( y0 y1 ) ( y0 y2 ) ( y1 y0 ) ( y1 y2 )
(7 y0 ) (7 y1 )
x1 x2
( y2 y0 ) ( y2 y1 )
1 27 4
2 14 7
= 1.86
The actual value is 2.0 since the above values were obtained from the polynomial
y( x ) x 2 3.
Similarly,
Hence
l0 ( x ) l ( x) l ( x)
L2 ( x ) f 1 f 2 f
l0 ( x k ) 0 l1 ( x k ) 1 l0 ( x k ) 2
| Error | 0.0008646.
x y sin x
0 0
/4 0.70711
/2 1.0
Solution We have
( / 6 0) ( / 6 / 2) ( / 6 0) ( / 6 / 4)
sin (0.70711) (1) 8 (0.70711) 1
6 ( / 4 0) ( / 4 / 2) ( / 2 0) ( / 2 / 4) 9 9
4.65688 0.51743.
9
Example Using Lagranges’ interpolation formula, find the form of the function y( x ) from
the following table.
x y
0 12
1 0
3 12
4 24
( x 3)( x 4) 2 x ( x 4) 2 x ( x 3)
= x 2 5 x 12.
y( x ) ( x 1)( x 2 5 x 12).
Example With the use of Newton’s divided difference formula, find log 10301. Given the
following divided difference table
x f ( x ) log 10 x f [ xk 1 , xk ] f [ xk 2 , xk , xk 1 ]
300 2.47714
0.00145
304 2.4829 0.00001
0.00140
305 2.4843 0
0.00140
307 2.4871
It is clear that the arithmetic in this method is much simpler when compare to that in
Lagrange’s method.
Exercises
10. Using the difference table in exercise 1, compute cos0.28 by Newton’s forward
difference interpolating formula with n 1, 2, 3, 4 and compare with the 5D-value
11. Using the values given in the table, find cos0.28 (in radian measure) by linear
interpolation and by quadratic interpolation and compare the results with the value
0.961 06 (exact to 5D).
First Second
x f(x)=cosx
difference difference