Skip to content

Commit 7f0c68e

Browse files
authored
Merge pull request #9 from BhawnaMehbubani/master
Add files via upload
2 parents 9e021d2 + 9b818fd commit 7f0c68e

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

Newton_forward_interpolation.cpp

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#include<stdio.h>
2+
int main()
3+
{
4+
int n,i,j;
5+
float sum=0,x[10],y[10][10],u,h,xp,p,q;
6+
printf("\n enter the number of elements: ");
7+
scanf("%d",&n);
8+
for(i=0;i<n;i++)
9+
{
10+
printf("\n Enter the value of x[%d] and y[%d][0]: ",i,i);
11+
scanf("%f%f",&x[i],&y[i][0]);
12+
}
13+
printf("\n Enter the value of x at which f(x) is required: ");
14+
scanf("%f",&xp);
15+
for(j=1;j<n;j++)
16+
{
17+
for(i=0;i<=(n-j);i++)
18+
{
19+
y[i][j]=y[i+1][j-1]-y[i][j-1];
20+
}
21+
}
22+
printf("Difference Table\n");
23+
printf("x\t y\t dy\t d2y\t d3y\t \n");
24+
for(i=0;i<n;i++)
25+
{
26+
printf("%0.2f",x[i]);
27+
for(j=0;j<n-i;j++)
28+
{
29+
printf("\t%0.2f",y[i][j]);
30+
}
31+
printf("\n");
32+
}
33+
h=x[1]-x[0];
34+
u=(xp-x[0])/h;
35+
sum=y[0][0];
36+
p=1;
37+
q=1;
38+
for(j=1;j<n;j++)
39+
{
40+
p = p*j;
41+
q = q*(u+1-j);
42+
sum = sum+(q*y[0][j]/p);
43+
}
44+
printf("\n The value of f(%0.2f)= %0.2f",xp,sum);
45+
}
46+

0 commit comments

Comments
 (0)