0% found this document useful (0 votes)
2 views3 pages

9 Lagrange Interpolation Method

The document explains the Lagrange Interpolation Method, which is used to estimate the value of a dependent variable based on observed data for an independent variable. It provides a formula for the method and outlines an algorithm for its implementation in C programming language, including a sample program. The document also distinguishes between interpolation and extrapolation, noting that the former is used for values within the observed data range, while the latter is for values outside that range.

Uploaded by

RishiKesh Das
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views3 pages

9 Lagrange Interpolation Method

The document explains the Lagrange Interpolation Method, which is used to estimate the value of a dependent variable based on observed data for an independent variable. It provides a formula for the method and outlines an algorithm for its implementation in C programming language, including a sample program. The document also distinguishes between interpolation and extrapolation, noting that the former is used for values within the observed data range, while the latter is for values outside that range.

Uploaded by

RishiKesh Das
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Lagrange Interpolation Method

In many real world applications of science and engineering, it is required to find the value of dependent variable
corresponding to some value of independent variable by analysing data which are obtained from some observation.
For example, suppose we have following sets of data tabulated for x (independent variable) and y (dependent
variable) :

----------------------------------------
| x: | x0 | x1 | x2 | x3 | ... | xn |
-----------------------------------
| y: | y0 | y1 | y2 | y3 | ... | yn |
----------------------------------------

Then the method of finding the value of y = f(x) corresponding to any value of x=xi within x0 and xn is called
interpolation. Thus interpolation is the process of finding the value of function for any intermediate value of the
independent variable. If we need to estimate the value of function f(x) outside the tabular values, then the process is
called extrapolation. However, in general, extrapolation is also included in interpolation.

There are different methods for interpolation for example: Newton’s Forward Interpolation, Newton’s Backward
Interpolation, Newton’s General Interpolation with divided difference, Lagrange Interpolation etc. In this article we
are going to develop an algorithm for Lagrange Interpolation.

Formula: Lagrange Interpolation Method

If y = f(x) takes the value of y0 , y1 , y2 , y3 , ... , yn corresponding to x0 , x1 , x2 , x3 , ... , xn then

y = f(x) = (x - x1)(x - x2)...(x - xn) * y0/(x0 - x1)(x0 - x2)...(x0 - xn)

(x - x0)(x - x2)...(x - xn) * y1/(x1 - x0)(x1 - x2)...(x1 - xn)

+ .... +

(x - x1)(x - x2)...(x - xn-1) * yn/(xn - x0)(xn - x1)...(xn - xn-1)

is known as Lagrange Interpolation Formula for unequal intervals and is very simple to implement on computer.

Algorithm
1. Start

2. Read number of data (n)

3. Read data Xi and Yi for i=1 ton n

4. Read value of independent variables say xp


whose corresponding value of dependent say yp is to be determined.

5. Initialize: yp = 0

6. For i = 1 to n
Set p = 1
For j =1 to n
If i ≠ j then
Calculate p = p * (xp - Xj)/(Xi - Xj)
End If
Next j
Calculate yp = yp + p * Yi
Next i

6. Display value of yp as interpolated value.

7. Stop

Program:
This program implements Lagrange Interpolation Formula in C Programming Language.

In this C program, x and y are two array for storing x data and y data respectively. xp is interpolation point given by
user and output of Lagrange interpolation method is obtained in yp.

#include<stdio.h>
#include<conio.h>

void main()
{
float x[100], y[100], xp, yp=0, p;
int i,j,n;
clrscr();
/* Input Section */
printf("Enter number of data: ");
scanf("%d", &n);
printf("Enter data:\n");
for(i=1;i<=n;i++)
{
printf("x[%d] = ", i);
scanf("%f", &x[i]);
printf("y[%d] = ", i);
scanf("%f", &y[i]);
}
printf("Enter interpolation point: ");
scanf("%f", &xp);
/* Implementing Lagrange Interpolation */
for(i=1;i<=n;i++)
{
p=1;
for(j=1;j<=n;j++)
{
if(i!=j)
{
p = p* (xp - x[j])/(x[i] - x[j]);
}
}
yp = yp + p * y[i];
}
printf("Interpolated value at %.3f is %.3f.", xp, yp);
getch();
}
Output:
Enter number of data: 5
Enter data:
x[1] = 5
y[1] = 150
x[2] = 7
y[2] = 392
x[3] = 11
y[3] = 1452
x[4] = 13
y[4] = 2366
x[5] = 17
y[5] = 5202
Enter interpolation point: 9
Interpolated value at 9.000 is 810.000.

You might also like