Wednesday, October 1, 2014

Implement the Newton’s interpolation using divided difference table.

#include
#include
#include
void main ()
{
  float x [10], y [10] [10], sum, p, u, temp;
  int i,n,j,k=0,f,m;
  float fact(int);
  clrscr();
  printf("\n How many points?? ");
  scanf("%d",&n);
  for(i=0; i
  {
   printf("\n\nenter the value of x%d: ",i);
   scanf("%f",&x[i]);
   printf("\n\nenter the value of f(x%d): ",i);
   scanf("%f",&y[k][i]);
  }
  printf("\n\nEnter X for finding f(x): ");
  scanf("%f",&p);

  for(i=1;i
  {
    k=i;
    for(j=0;j
    {
     y[i][j]=(y[i-1][j+1]-y[i-1][j])/(x[k]-x[j]);
     k++;
    }
  }
  printf("\n_____________________________________________________\n");
  printf("\n  x(i)\t   y(i)\t    y1(i)    y2(i)    y3(i)    y4(i)");
  printf("\n_____________________________________________________\n");
  for(i=0;i
  {
    printf("\n %.3f",x[i]);
    for(j=0;j
    {
     printf("   ");
     printf(" %.3f",y[j][i]);
    }
   printf("\n");
  }

  i=0;
  do
  {
   if(x[i]
    k=1;
   else
    i++;
  }while(k != 1);
  f=i;

  sum=0;
  for(i=0;i
  {
   k=f;
   temp=1;
   for(j=0;j
   {
    temp = temp * (p - x[k]);
    k++;
   }
    sum = sum + temp*(y[i][f]);
  }
  printf("\n\n f(%.2f) = %f ",p,sum);
  getch();

}

No comments:

Post a Comment