Tweet
// Lagrange's Interpolation Formula
#include<stdio.h>
main()
{
int i,n,j;
float x[20],y[20],d[20],a[20][20],u=1.0,s=0.0;
printf("\nLagrange's Interpolation Formula : ");
printf("\n**********************************\n");
printf("\nEnter the no. of data : ");
scanf("%d",&n);
printf("\nEnter the values of x[i] & y[i] : \n");
printf("\tx\ty\n");
for(i=1;i<=n;i++)
scanf("%f%f",&x[i],&y[i]);
printf("\nEnter the interpolation point : ");
scanf("%f",&x[0]);
for(i=1;i<=n;i++)
{
d[i]=1.0;
for(j=1;j<=n;j++)
{
if(j==1)
a[i][j]=x[0]-x[j];
else
a[i][j]=x[i]-x[j];
d[i]=d[i]*a[i][j];
}
s=s+y[i]/d[i];
u=u*a[i][j];
}
printf("\ny(%f)=%f\n",x[0],u*s);
}
Lagrange's Interpolation Formula in C
Posted by
LAHAUL SETH
~
Lagrange's Interpolation Formula in C
2011-12-22T08:31:00+05:30
LAHAUL SETH
Numerical Methods
|
Programming in C
|
Comments
Lagrange's Interpolation Formula in C
2011-12-22T08:31:00+05:30
LAHAUL SETH
Numerical Methods
|
Programming in C
|