Featured Post

Step Wise Project Planning

Planning is the most difficult process in project management. The framework described is called the Stepwise method to help to distinguis...

  1. Home

To implement Lagrange’s Interpolation Formula.

To implement Lagrange’s Interpolation Formula.

#include<stdio.h>
#include<conio.h>
#define MAX 100
main()
{
float ax [MAX+1],ay[MAX+1],nr,dr,x,y=0;
int i,j,n;
clrscr();
printf("Enter the value of n \n");
scanf("%d", &n);
printf("Enter the set of values \n");
for(i=0;i<=n;i++)
scanf("%f%f",&ax[i],&ay[i]);
puts("Enter the value of x for which value of y is wanted");
scanf("%f",&x);
for(i=0;i<=n;i++)
{
nr=dr=1;
for(j=0;j<=n;j++)
if (j!=1)
{
nr *= x-ax[j];
dr *= ax[i]-ax[j];
}
y += (nr/dr) *ay[i];
}
printf("When x=%4.1f y=%7.1f \n",x,y);
}












Output



Lagrange Interpolation Formula

Previous
Next Post »