#include<stdio.h>
#include<math.h>
void main()
{
float ax[10],y[10];
float x,numsum=1,densum=1,k;
int i,j,n;
printf("Enter the number of terms ");
scanf("%d",&n);
printf("\n=======================================================\n");
printf("Enter the array ax ");
for(i=0;i<n;i++)
{
printf("\nEnter the value of ax[%d] = ",i);
scanf("%f",&ax[i]);
}
printf("\n=======================================================\n");
for(i=0;i<n;i++)
{
printf("Enter the value of y[%d] = ",i);
scanf("%f",&y[i]);
}
printf("\nEnter the interpolation point ");
scanf("%f",&x);
k=0;
for(i=0;i<n;i++)
{
numsum=1;
densum=1;
for(j=0;j<n;j++)
{
if(i!=j)
{
numsum=numsum*(x-ax[j]);
densum=densum*(ax[i]-ax[j]);
}
}
k=k+(numsum/densum)*y[i];
}
printf("\nValue at %f is %f ",x,k);
getchar();
}
Monday, 17 October 2011
Lagrange's Interpolation Formula
Subscribe to:
Post Comments (Atom)
wrong output
ReplyDeletenice post
ReplyDeleteC programs for CBNST