Newton Backward Interpolation Program in C

Date:

Category: Numerical Techniques Lab


Newton Backward Interpolation Concepts and Program in C

This tutorial is helpful for computer science student to understand the concepts of interpolation, extrapolation in numeric techniques. This tutorial is also helpful for the students in implementing the program for backward interpolation in c programming language.
What is Interpolation ?
What is extrapolation ?
What is Newton Backward Interpolation Formula ?
 
newton interpolation program in c

Newton Backward Interpolation in C

Interpolation

Interpolation is a method of making the estimate of  the value of a function for any intermediate value of the independent variable.
Extrapolation
 
Extrapolation is a  process of computing the value of the function outside the given range.

What is Newton’s Forward and Backward Interpolation ?

Given the set of (n+1) values of x and y, it is required to find y n (x), a polynomial of the nth degree such that y and y n (x) agree at the tabulated points. The values of x be equidistant i.e. xi = x0 + ih, i=0, 1, 2…..n.
Since y n(x) is a polynomial of the nth Degree                                                              
y n(x) =a0 +a1(x-x0) +a2(x-x0)(x-x1)………….+an(x-x0)………….(x-x n-1)
Imposing now the condition that y and yn(x) should agree at the set of tabulated points and applying x=x0+ph we get Newton’s Forward difference interpolation formula which is given by.
y n(x) = y0 + pDy0 + p (p-1) / 2! D2y0+ p (p-1) (p-2) / 3! D3y0 + ……… + p (p-1) (p-2)…. (p-n+1) / n! Dn y0
It is useful for interpolation near the beginning of a set of tabular values.

Similarly if yn (x) chosen in the form

y n(x) = a0+a1 (x-x n) + a2 (x-x n) (x-x n-1) +……..an(x-x n) (x-x n-1)……(x-x1

then we have
y n (x) = y n + pÑy n + p(p+1) / 2 Ñ2 y n + ………+ p(p+1)…..(p+n-1) / n! Ñ n y n           where p= x-x n / h

This is newton’s backward difference interpolation formula and it uses tabular values to the left of y n. It is useful for interpolation near the end of the tabular values.

Newton Backward Interpolation Program in C

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(“nhow many record you will be enter: “);
  scanf(“%d”,&n);

   for(i=0; i  {
   printf(“nnenter the value of x%d: “,i);

   scanf(“%f”,&x[i]);
   printf(“nnenter the value of f(x%d): “,i);
   scanf(“%f”,&y[k][i]);
  }
  printf(“nnEnter X for finding f(x): “);
  scanf(“%f”,&p);
  for(i=1;i  {
    for(j=i;j    {
     y[i][j]=y[i-1][j]-y[i-1][j-1];
    }
  }
 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<=i;j++)
    {
     printf(”   “);
     printf(” %.3f”,y[j][i]);
    }
   printf(“n”);
  }
  i=0;
  do
  {
   if(x[i]
    k=1;
   else
    i++;
  }while(k != 1);
  f=i+1;
  u=(p-x[f])/(x[f]-x[f-1]);
  printf(“nn u = %.3f “,u);
  n=n-i+1;
  sum=0;
  for(i=0;i  {
   temp=1;
   for(j=0;j   {
    temp = temp * (u + j);
   }
    m=fact(i);
    sum = sum + temp*(y[i][f]/m);
  }
  printf(“nn f(%.2f) = %f “,p,sum);
  getch();
}
float fact(int a)
{
  float fac = 1;
  if (a == 0)
   return (1);
  else
   fac = a * fact(a-1);
  return(fac);
}
Output
newton forward interpolation formula
 

Leave a Comment

x