LAGRANGE'S INTERPOLATION IN C
//program to implement lagranges interpolation.
#include<stdio.h>
int main()
{
int i,j,n;
printf("\n Enter the number of entries :\n);
scanf("%d",&n);
float x[n],y[n],nr,dr,xv,yv=0.0;
printf("\n Enter the values of x and y :\n \n);
for(i=0;i<n;i++)
scanf("%f%f",&x[i],&y[i]);
printf("\n Enter the the value of x to find y :\n);
scanf("%f",&xv);
if(j!=i)
{ nr=nr*(xv-x[j]);
dr=dr*(x[i]-x[j]);
}
}
yv=yv+((nr/dr)*y[i]);
}
printf("The value of y for x= %f is y= %f \n ",xv,yv);
return 0;
}
#include<stdio.h>
int main()
{
int i,j,n;
printf("\n Enter the number of entries :\n);
scanf("%d",&n);
float x[n],y[n],nr,dr,xv,yv=0.0;
printf("\n Enter the values of x and y :\n \n);
for(i=0;i<n;i++)
scanf("%f%f",&x[i],&y[i]);
printf("\n Enter the the value of x to find y :\n);
scanf("%f",&xv);
for(i=0;i<n;i++)
{
nr=1;
nr=1;
dr=1;
for(j=0;j<n;j++)
{if(j!=i)
{ nr=nr*(xv-x[j]);
dr=dr*(x[i]-x[j]);
}
}
yv=yv+((nr/dr)*y[i]);
}
printf("The value of y for x= %f is y= %f \n ",xv,yv);
return 0;
}
Comments
Post a Comment