// Newton Backward Interpolation
#include<stdio.h>
#include<conio.h>
int main()
{
int i,j,num;
float data[10][10],u,abc,x,ch1=0.0,ch=1;
//char str[80];
printf("\n *** Welcome to the calculation in Newton Backward Interpolation***");
printf("\n\n Enter the number of values do u wanna Enter:\n Enter Your Choice:");
scanf("%d",&num);
printf("\n\n Enter the set of data values:");
for(i=0;i<num;i++)
{
printf("\n Enter data value x(%d) is:",i+1);
scanf("%f",&data[i][0]);
}
printf("\n\n\t *** Enter The Set Of Function Values ***");
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 Newton Backward 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[num-1][0])-(data[num-2][0]));
u=((x)-(data[num-1][0]))/abc;
ch1=data[num-1][1];
for(i=1;i<num;i++)
{
ch=ch*((u+(i-1))/(i));
//ch1=ch1+(data[0][i+1])*(ch);
ch1=ch1+((data[num-i-1][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;
}
Gurpreet Singh
No comments:
Post a Comment