Newton's Backward interpolation
Problem: The population of a town is given below as thousands
Year : 1891 1901 1911 1921 1931
Population : 46 66 81 93 101
Find the population of 1895 ?
Program:
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
main()
{
float x[20],y[20],f,s,d,h,p;
int j,i,k,n;
printf("enter the value of the elements :");
scanf("%d",&n);
printf("enter the value of x:\n");
for(i=1;i<=n;i++)
{
scanf("%f",&x[i]);
}
printf("enter the value of y:\n");
for(i=1;i<=n;i++)
{
scanf("%f",&y[i]);
}
h=x[2]-x[1];
printf("enter the searching point f:");
scanf("%f",&f);
s=(f-x[n])/h;
d=y[n];
p=1;
for(i=n,k=1;i>=1,k<n;i--,k++)
{
for(j=n;j>=1;j--)
{
y[j]=y[j]-y[j-1];
}
p=p*(s+k-1)/k;
d=d+p*y[n];
}
printf("for f=%f ,ans is=%f",f,d);
getch();
}
Output:
Enter the value of the elements :5
Enter the value of x:
1891
1901
1911
1921
1931
Enter the value of y:
46
66
81
93
101
Enter the searching point f:1895
For f=1895.000000 ,ans is=54.852795