C program of Newton Backward Interpolation Formula

# C program of Newton Backward Interpolation Formula

634
12
SHARE

C program of Newton Backward Interpolation formula : Newton has proposed several methods of estimating the values of any number at certain point by learning the behavior of previous values. Newton’s Backward interpolation formula is one of them. Newton’s backward interpolation is based on interpolating the newton’s polynomial which is sometimes also referred as Newton’s divided differences interpolation polynomial because the coefficients of the polynomial are calculated using divided differences.

(From Wikipedia) :Given a set of k + 1 data points

where no two xj are the same, the interpolation polynomial in the Newton form is a linear combination of Newton basis polynomials

with the Newton basis polynomials defined as

for and . The coefficients are defined as

where      is the notation for divided differences.

Thus the Newton polynomial can be written as

Now

If the nodes are reordered as , the Newton Polynomial becomes:

If    are equally spaced with x= and

for ,then,

is called the Newton Backward Divided Difference Formula.

Now Let us see how to implement above logic using . Below which takes number of values of x as input from user and then takes values of x and corresponding values of y. Then it asks user at which point he wish to estimate the value and the displays the output value of N(x) at that point.

### C program of Newton Backward Interpolation Formula :

```#include<stdio.h>
#include<conio.h>
#include<math.h>
#include<process.h>
#include<conio.h>
#include<stdlib.h>

int main()
{
int n;
int i,j,k;
float mx[10],my[10];
float x,h,x0=0,fun=0,p;
float y0,sum=0,diff[20][20];
float y1,y2,y3,y4;

printf("----------------------------------------------------------------------\n");
printf("-------------------made by C code champ ------------------------------\n");
printf("----------------------------------------------------------------------\n");
printf("\n\n\t!! NEWTON'S BACKWARD INTERPOLATION FORMULA !! ");
printf("\n\n Enter the values of x you want to enter -> ");
scanf("%d",&n);

printf("\n\n Enter the value in the form of x : ");
for(i=0;i<n;i++)
{
printf("\n Enter the value of x[%d] : ",i+1);
scanf("%f",&mx[i]);
}

printf("\n\n Enter the value in the form of y : ");
for(i=0;i<n;i++)
{
printf("\n Enter the value of y[%d] : ",i+1);
scanf("%f",&my[i]);
}

printf("\n\n Enter the value of x for which u want the value of y : ");
scanf("%f",&x);

// Calculation and processing section.
h=mx[1]-mx[0];
for(i=0;i<n-1;i++)
diff[i][1]=my[i+1]-my[i];

for(j=2;j<=4;j++)
for(i=0;i<n-j;i++)
diff[i][j]=diff[i+1][j-1]-diff[i][j-1];
i=0;

while(!mx[i]>x)
i++;

x0=mx[i];
sum=0;

y0=my[i];
fun=1;

p=(x-x0)/h;
sum=y0;

for(k=1;k<=4;k++)
{
fun=(fun*(p-(k-1)))/k;
sum=sum+fun*diff[i][k];
}

// Output
printf("\n When x = %6.4f , y = %6.8f\n\n",x,sum);
getch();
system("pause");
}```

We hope you all have enjoyed the C program of Newton Backward Interpolation formula i.e. backward divided difference. If you have any issues with above code, ask us in form of comments.

SHARE
Previous articleC program of Booth’s multiplication algorithm
Well, I am software programmer and love to code. My hobbies is to do Hacking, Coding, Blogging, Web Designing and playing online games. Feel free to contact me at shiviskingg@gmail.com or lokesh@hackingloops.com