#include "conio.h"
int i,j,k,loop_var=0;
int n;
float inter;
float x[50];
float y[50];
float forward[50][50];
float result_s[50];
float final_res=0;
float s,cumm_sum=1;
float factorial(int);
float cal(void);
void draw_table(float t[50][50]);
void main ()
{
clrscr ();
printf ("Forward difference Method:\n\n");
printf ("\n-------------------------------------\n\n\n");
printf ("Enter number of terms: ");
scanf("%d",&n);
clrscr ();
for(i=0; i
{
printf("Enter x%d:\t",i);
scanf("%f",&x[i]);
printf("Enter f(x%d):\t",i);
scanf("%f",&y[i]);
printf("\n");
}
printf ("\n\n-------------------------------------\n\n\n");
printf("\nEnter the intermediate term:\t");
scanf("%f",&inter);
printf("\n\nThe Estimated Value is : %f",cal ());
getch ();
}
float cal ()
{
s = (inter-x[0]) / (x[1] - x[0]);
loop_var = n ;
for(i=0; i
{
for(j=0; j
{
forward[i][j] = 0;
}
}
for(i=0; i
{
forward[i][0] = y[i+1] - y[i];
}
for(j=0; j<=n-1; j++)
{
for(i=1 ; i
{
forward[i-1][j+1] = forward[i][j] - forward[i-1][j] ;
}
loop_var--;
}
for(i=0; i
{
cumm_sum *= (s-i);
result_s[i] = cumm_sum;
}
for(i=0; i
{
final_res += ((forward[0][i] * result_s[i] ) / factorial(i+1));
}
final_res +=y[0];
printf ("\n\n\n-------------------------------------\n\n\n");
printf("The Forward Difference Table Is As Follows : \n\n\n");
draw_table(forward);
return final_res;
}
float factorial(int num)
{
int fact = 1.0;
while (num > 0)
{
fact *= num ;
num--;
}
return fact;
}
void draw_table(float t[50][50])
{
for(i=0,k=n-1; i
{
for(j=0; j
{
if (j
printf("%f\t", t[i][j]);
}
printf("\n\n");
}
printf ("\n\n\n-------------------------------------\n\n\n");
}
0 comments:
Post a Comment