newton backward interpolation program in c
Numerical Techniques Lab

Newton Backward Interpolation Program in C

Newton Interpolation Program in C

I have explained the newton interpolation program in c programming here in this post. This tutorial helps computer science students understand the concepts of interpolation, extrapolation in numerical techniques.

This tutorial helps the students implement the program for backward interpolation in the c programming language.

Frequently Asked Questions

This newton interpolation program based tutorial will help the computer science graduate to get the answer to the following questions

  • What is Interpolation?
  • What is extrapolation?
  • What is Newton Backward Interpolation Formula?
  • How to make a program in c for the newton backward interpolation?

Newton Backward Interpolation Program in C

What is Interpolation ?

Interpolation is a method of making the estimate of  the value of a function for any intermediate value of the independent variable.

What is 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 helpful for interpolation near the beginning of a set of tabular values.

Similarly, if you (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 helpful for interpolation near the end of the tabular values.

Newton Backward Interpolation Program in C

Program to implement the newton interpolation program in c for backward method programing language is give below. Students are suggested to implement this program in C. If you face any problem or error then you may ask in the comment.

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

                    for(i=0; i <n; 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(“nnEnter X for finding f(x): “);
                          scanf(“%f”,&p);
                                for(i=1;i <n:i++)
                               {
                                    for(j=i;j <n;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 Reply

Your email address will not be published. Required fields are marked *