Lagrange Interpolation

3. LAGRANGE INTERPOLATION METHOD
(LAGRANGE POLYNOMIAL):
An alternate method of interpolation is to use polynomial fits to the
available values to interpolate between those values. If there are N
data values, a polynomial of degree N-1 can be found that will pass
through all the points.
The Lagrange polynomials provide a convenient alternative to
solving the simultaneous equations that result from requiring the
polynomials to pass through the data values. This is a particularly
convenient way to interpolate among tabulated values with
polynomials.
An advantage of Lagrange Interpolation is that the method does
not need evenly spaced values in x. However, it is usually
preferable to search for the nearest value in the table and then use
the lowest-order interpolation consistent with the functional form
of the data.
Example 3.1:
x
f(x)
0
3
2
60
4
90
10
120
f (8)  ?
f ( x) 
( x  2)(x  4)(x  10)
( x  0)(x  4)(x  10)
3 
 60
(0  2)(0  4)(0  10)
( 2  0)(2  4)(2  10)
( x  0)(x  2)(x  10)
( x  0)(x  2)(x  4)

 90 
 120
(4  0)(4  2)(4  10)
(10  0)(10  2)(10  4)
x  8  f (8)  109.8
1. Lagrange Interpolation with Matlab
clc;clear
x=[0 2 4 10];
f=[3 60 90 120];
interp1(x,f,8,'spline')
2. Lagrange Interpolation with Matlab (Reading data from a text file)
clc;clear
v=load ('c:\saha\data.txt')
interp1(v(:,1),v(:,2),8,'spline')
data.txt
0,3
2,60
4,90
10,120