/*
Newtons backward formula
x: 1 1.10 1.20 1.30
y: .4158 .8912 .9320 .9636
Compute::f(1.40)=?
*/
#include<conio.h>
#include<stdio.h>
#define n 4
void main()
{
float x[n],y[n][n],xf,fx,u,h;
int j,i,index,f=1;
for(i=0;i<n;i++)
{
printf("\nEnter x[%d] & y[%d][0]",i+1,i+1);
scanf("%f%f",&x[i],&y[i][0]);
}
for(j=1;j<n;j++)
{
for(i=0;i<n;i++)
y[i][j]=y[i+1][j-1]-y[i][j-1];
}
for(i=0;i<n;i++)
{
for(j=0;j<n-1;j++)
printf("%f\t",y[i][j]);
printf("\n");
}
printf("\nEnter x");
scanf("%f",&xf);
index=n-1;
h=x[1]-x[0];
u=(xf-x[index])/h;
fx=y[index][0];
for(i=1;i<n;i++)
{
if(i!=1)
u=u*(u+i-1);
f=f*i;
fx=fx+(u*y[index][i])/f;
}
printf("\nResult %f",fx);
getch();
}
Comments
Post a Comment