// Newton Foward interpolation
#include<stdio.h>
#include<conio.h>
int main()
{
int i,j,num;
float data[10][10],u,abc,x,ch1,ch=1;
printf("\n *** Welcome to the calculation in Newton Forward Interpolation ***");
printf("\n\n Enter the number of values do u wanna Enter:\n Enter Your Choice:");
scanf("%d",&num);
for(i=0;i<num;i++)
{
printf("\n Enter data value x(%d) is:",i+1);
scanf("%f",&data[i][0]);
}
for(i=0;i<num;i++)
{
printf("\n Enter function value y(%d)is:",i+1);
scanf("%f",&data[i][1]);
}
for(j=2;j<num+1;j++)
{
for(i=0;i<num-1;i++)
{
data[i][j]=((data[i+1][j-1])-(data[i][j-1]));
}
}
printf("\n The Forward difference Table is:");
printf("\n x f(x)");
for(i=0;i<num;i++)
{
printf(" %dDD ",i);
// if(i==4)
// break;
}
for(i=0;i<num;i++)
{
printf("\n");
for(j=0;j<num+1-i;j++)
{
printf(" %f",data[i][j]);
}
}
printf("\n\n Enter the value of x:\n Enter Your Choice:");
scanf("%f",&x);
abc=((data[1][0])-(data[0][0]));
u=(x-data[0][0])/abc;
ch1=data[0][1];
for(i=1;i<num;i++)
{
ch=ch*((u-(i-1))/i);
ch1=ch1+(data[0][i+1])*(ch);
}
printf("\n\n\t Hence The value at the function at x=%f is =%f",x,ch1);
printf("\n\n\t\t\t *** Bye Bye ***");
getch();
return 0;
}
Garry
No comments:
Post a Comment