(19)
Name- Ayush Thapa
Semester-vth Sem
Session-2021
Subject- Numerical Analysis Practical
Reg. No- 0232105030184
/*............................................NEWTON'S BACKWARD METHOD...........................................*/
/*Write a programme in computer language to compute f(12.3), correct upto 6 decimal places
by using Newton's backward Interpolation formula from the following table-
x f(x)
______________
11.5 0.26969
11.6 0.33837
11.8 0.39544
11.9 0.40022
12.1 0.38332
12.4 0.32257*/
#include<stdio.h>
#define ORDER 3
int main()
{
float x[10],y[10],diff[10][ORDER+1];
float nr=1.0,dr=1.0,X,p,h,Y;
int n,i,j,k;
printf("Enter the value of n:\n ");
scanf("%d",&n);
printf("Enter the value of x and Y:\n ");
for (i=0;i<n;i++)
scanf("%f%f",&x[i],&y[i]);
printf("\n Enter the value of x:");
scanf("%f",&X);
h=x[1]-x[0];
for (i=1;i<n;i++)
diff[i][1]=y[i]-y[i-1];
for (j=2;j<=ORDER;j++)
for (i=0;i<=n-j;i++)
diff[i][j]=diff[i][j-1]-diff[i][j-1];
i=0;
while (!(x[i]>X))
i++;
i--;
(20)
p=(X-x[i])/h;
Y=y[i];
for (k=1;k<=ORDER;k++)
{
nr=nr*(p+k-1);
dr=dr*k;
Y=Y+(nr/dr)*diff[i][k];
}
printf("when x=%6.2f,y=%8.4f",X,Y);
}
/*.....................................................OUTPUT..................................................*/
Enter the value of n:
6
Enter the value of x and Y:
11.5 0.26969
11.6 0.33837
11.8 0.39544
11.9 0.40022
12.1 0.38332
12.4 0.32257
Enter the value of x:12.3
when x= 12.30,y= 0.3495
--------------------------------
Process exited after 149.7 seconds with return value 0
Press any key to continue . . .