/******************************************
Lagrange's Interpolation
******************************************/
/* http://native-code.blogspot.com */
#include<stdio.h>
#include<conio.h>
#define MAX 20
void main()
{
float s,p,z;
float x[MAX],y[MAX];
int i,n,j,k;
s=0.0F; p=1.0F;
clrscr();
//--------------------------
printf("\nEnter the total number of terms:");
scanf("%d",&n);
printf("\n\nEnter the table");
printf("\nX\tY\n");
for(i=0;i<n;i++)
{
scanf("%f",(x+i));
scanf("%f",(y+i));
}
//--------------------------
printf("\nEnter the interpolation point:");
scanf("%f",&z);
//--------------------------
for(k=0;k<n;k++)
{
p=1.0F;
for(j=0;j<n;j++)
{
if(j!=k)
p*=((z-x[j])/(x[k]-x[j]));
}
s+=(y[k]*p);
printf("\nSum=%f",s); // DEBUG DATA
}
printf("\n\n\nRESULT BY LAGRANGE'S INTERPOLATION:%.3f",s);
getch();
} // end of main
/* http://native-code.blogspot.com */
Post a Comment