-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathforward interpolation.c
More file actions
56 lines (49 loc) · 1.1 KB
/
forward interpolation.c
File metadata and controls
56 lines (49 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include<stdio.h>
#include<conio.h>
void main()
{
int n,i,j;
float arrx[10];
float arry[10][10];
printf("Enter the number of observations");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("Enter the observation value at %d",(i+1));
scanf("%f",&arrx[i]);
}
for(j=0;j<n;j++)
{
printf("Enter the observation value of y at %d",(j+1));
scanf("%f",&arry[0][j]);
}
for(i=1;i<n;i++)
{
for(j=0;j<(n-i);j++)
{
arry[i][j]=arry[i-1][j+1]-arry[i-1][j];
}
}
printf("then the difference table is\n");
for(j=0;j<n;j++)
{
printf("%f",arrx[j]); printf("\t");
for(i=0;i<(n-j);i++){
printf("%f\t",arry[i][j]);
}
printf("\n");
}
float x;
printf("enter the x for which you want to find f(x)");
scanf("%f",&x);
float fx;
float h=arrx[1]-arrx[0];
float p=(x-arrx[0])/h;
printf("p=%f",p);
fx=arry[0][0]+p*arry[1][0]+(p*(p-1)/2*arry[2][0])+(p*(p-1)*(p-2)/6*arry[3][0]);
if(n>4)
fx+=(p*(p-1)*(p-2)*(p-3)/24*arry[4][0]);
if(n>5)
fx+=(p*(p-1)*(p-2)*(p-3)*(p-4)/120*arry[5][0]);
printf("\nso fx=%f",fx);
}