Showing posts with label PROGRAM FOR NEWTON’S FORWARD DIFF. FORMULA. Show all posts
Showing posts with label PROGRAM FOR NEWTON’S FORWARD DIFF. FORMULA. Show all posts

Tuesday, August 2, 2016

PROGRAM FOR NEWTON’S FORWARD DIFF. FORMULA

/*PROGRAM FOR NEWTON’S FORWARD DIFF. FORMULA*/


#include<stdio.h>
#include<conio.h>
#define n 4
void main()
{
float nr=1,dr=1,p,x,y;
float ax[n],ay[n],delta[n-1][n-1];
int i=0,j=0,k;
clrscr();
for(i=0;i<n;i++)
{
printf("\n Enter the value of ax and ay:\n");
scanf("%f%f",&ax,&ay);
}
printf("\n Enter the value of x:");
scanf("%f",&x);
for(i=0;i<n-1;i++)
{
delta[i][0]=(ay[i+1]-ay[i]);
printf("\n %f",delta[i][0]);
}
for(j=1;j<n-1;j++)
{
for(i=0;i<(n-1-j);i++)
{
delta[i][j]=delta[i+1][j-1]-delta[i][j-1];
printf("\n\n%f",delta[i][j]);
}
}
for(i=0;i<n-1;i++)
{
printf("\n\n");
}
for(i=0;i<n-1-j;i++)
{
printf("%f",delta[j][i]);
}
p=(x-ax[0]/ax[1]-ax[0]);
y=ay[0];
for(k=0;k<n-1;k++)
{
nr=nr*(p-k);
dr=dr*(k+1);
y+=((nr/dr)*delta[0][k]);
}
printf("ANSWER: VALUE OF Y AT%f IS %f",x,y);
getch();
}


/*OUTPUT
Enter the value of ax and ay:
35
13229
Enter the value of ax and ay:
45
31368
Enter the value of ax and ay:
55
55593
Enter the value of ax and ay:
65
87089
Enter the value of x:50
18139.000000
24225.000000
31496.000000
6086.000000
7271.000000
1185.000000
ANSWER: VALUE OF y AT 50.000000 IS 42645.687500*/