## Lagrange's Interpolation Method

Back to Programming

### Description

In numerical this method is used for polynomial interpolation. This method is used to find a polynomial by taking certain values at arbitrary points. The set of points are given such that no two points are of the same values, and this function works in such a way that the functions coincide at each point.

DERIVATION

Let y = f(x) be a real valued function defined in an interval [a, b] and let  be (n + 1) distinct points in the intervals at which the respective values  are given.

Assume the polynomial

This is called the Lagrangian function.

Since

Since

It should be in the form:

i.e.

Thus we have

Using the product notation, we have,

Again, we can write

Differentiating with respect to x we get

Now,

Therefore,

Thus, the interpolating formula can be written as:

GRAPHICAL REPRESENTATION

### Algorithm

INPUT:

The values of f(x) and x with the value for which the f(x) is to be calculated

OUTPUT:

The value of f(x) for the required x

PROCESS:

Step 1: [Taking the inputs from the user]
Read n [The number of points]
for i = 1 to n repeat
Read x[i] [The values of x]
[End of ‘for’ loop]
for i = 1 to n repeat
Read y[i] [the values of f(x)]
[End of ‘for’ loop]
Read x1 [The point of interpolation]

Step 2: [Lagrange’s Interpolation]
Set u ← 1.0
Set s ← 0.0
for i = 1 to n repeat
Set d[i] ← 1.0
for j = 1 to n repeat
If j = i then
Set a[i][j] ← x1 - x[j]
else
Set a[i][j] ← x[i] - x[j]
[End of ‘if’]
Set d[i] ← d[i] × a[i][j]
[End of ‘for’ loop]
Set s ← s + y[i]/d[i]
Set u ← u × a[i][i]
[End of ‘for’ loop]
for i = 1 to n repeat
Print x[i], y[i]
[End of ‘for’ loop]
Print u × s
[End of Lagrange’s Interpolation]

### Code

1. This polynomial can be used on functions that are tabulated at equal intervals as well as on the functions which are tabulated at unequal intervals.

2. It has an important theoretical role in the development of numerical differentiation and numerical integration of the function.