Monday, November 17, 2014

Backward Differences Generation For Interpolation



C Program for backward differences generation for interpolation

#include
#include
#include
#include
void main()
{
double y[20], x[20];
int I,j,k,num;
printf("\n Backward differences generation for interpolation");
printf("\n\n Enter the value of x and y(x) ");
scanf("%d",&num);
for(i=0;i
{
printf("\n Enter value of x %d:",i);
scanf("%lf”,&x[i]);
printf("\n Enter value of y %d:",i);
scanf("%lf",&y[i][0]);
}
k=0;
for(j=1;j
{
k++;
for(i=num;i>=k;i--)
{
y[i][j]=y[i][j-1]-y[i-1][j-1];
}
}
k=num;\
printf("\n Backward difference table\n");
printf("\n\tx\ty\tDy\tD2y\tD3y\tD4y\tD5y\tD6y\n");
for(i=0;i
{
printf("\nx%d=%4.2lf",I,x[i]);
for(j=0;j
{
printf("\t%4.2lf",y[i][j]);
}
printf("\n");
}
}

Output

Backward differences generation for interpolation
Enter the value of x and y =f(x):3
Enter value of x0:1
Enter value of x0:1
Enter value of x1:2
Enter value of x1:2
Enter value of x2:3
Enter value of x2:3
The backward difference table is as follows
X       y        Dy     D2y   D3y   D4y   D5y   D6y
X0     =1.00          1.00
X1     =2.00          2.00            1.00
X2     =3.00          3.00            1.00            0.00

C Program for backward differences generation for interpolation

#include
#include
#include
#include
 void main()
{
   double y[20][20], x[20];
   int i, j, k, num;
   printf("\nBackwad differences generation for Interpolation");
   printf("\n\nEnter the value of x and y = f(x)");
   scanf("%d", &num);
    for (i = 0; i < num; i++)
    {
      printf("\nEnter value of x%d : ", i);
      scanf("%lf", &x[i]);
      printf("\nEnter value of y%d : ", i);
      scanf("%lf", &y[i][0]);
    }
   k = 0;
   for (j = 1; j < num; j++)
   {
      k++;
      for (i = num - 1; i >= k; i--)
      {
         y[i][j] = y[i][j - 1] - y[i - 1][j - 1];
      }
   }

   k = num;
   printf("\nBackward Difference Table\n");
   printf("\n\tx\ty\tDy\tD2y\tD3y\tD4y\tD5y\tD6y\n");

   for (i = 0; i < num; i++)
   {
      printf("\nx%d    = %4.2lf", i, x[i]);
      for (j = 0; j < i + 1; j++)
     {
         printf("\t%4.2lf ", y[i][j]);
      }
      printf("\n");
   }
}

Output

Backwad differences generation for Interpolation

Enter the value of x and y = f(x) : 3
Enter value of x0 : 1
Enter value of y0 : 1
Enter value of x1 : 2
Enter value of y1 : 2
Enter value of x2 : 3
Enter value of y2 : 3

The backward difference table is as follows . . .

x    y    Dy    D2y    D3y    D4y    D5y    D6y

x0    = 1.00    1.00

x1    = 2.00    2.00     1.00

x2    = 3.00    3.00     1.00     0.00

No comments:

Post a Comment