#include "stdio.h"
#include "conio.h"
int i,j,k,loop_var=0;
int n;
float inter;
float x[50];
float y[50];
float backward[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 ("Backward 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 ()
{
loop_var = 0;
s = ( inter - x[n-1] ) / ( x[1] - x[0] );
for(i=0; i
{
for(j=0; j
{
backward[i][j] = 0;
}
}
for(i=n-1; i>0; i--)
{
backward[i-1][0] = y[i] - y[i-1];
}
for(j=1; j
{
for(i=n-1; i>loop_var; i--)
{
backward[i][j] = backward[i][j-1] - backward[i-1][j-1];
}
loop_var++;
}
for(i=0 ; i
{
cumm_sum *= (s+i);
result_s[i] = cumm_sum;
}
for(i=0; i
{
final_res += ((backward[n-2][i] * result_s[i] ) / factorial(i+1));
}
final_res +=y[n-1];
printf ("\n\n\n-------------------------------------\n\n\n");
printf("The Backward Difference Table Is As Follows : \n\n\n");
draw_table(backward);
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; i
{
for(j=0; j
{
if (j<=i)
printf("%f\t", t[i][j]);
}
printf("\n\n");
}
printf ("\n\n\n-------------------------------------\n\n\n");
}
0 comments:
Post a Comment