This formula is mainly used for interpolating the values of y near the beginning of a set of tabular values and for extrapolating values of y, a short distance backward from y0.
Forward Differences: The differences y1 – y0, y2 – y1, y3 – y2, ……, yn – yn–1, called the first forward differences. Thus the first forward differences are :
NEWTON’S GREGORY FORWARD INTERPOLATION FORMULA :
Example: What will be the value of Sin 52 as per the following data table?
Solution:
f(Sin 52)=?
Forward Differences: The differences y1 – y0, y2 – y1, y3 – y2, ……, yn – yn–1, called the first forward differences. Thus the first forward differences are :
Thus Let us first construct the backward difference table for the given data:
Forward difference table
NEWTON’S GREGORY FORWARD INTERPOLATION FORMULA :
Example: What will be the value of Sin 52 as per the following data table?
A0
|
450
|
500
|
550
|
600
|
Sin A
|
0.7071
|
0.7660
|
0.8192
|
0.8660
|
Solution:
f(Sin 52)=?
Forward difference table
here
hence
f(Sin 52)= 0.7071 +(1.4)(0.0589)+[(1.4)(1.4-1)(-.0057)]/!2 +[(1.4)(1.4-1)(1.4-2)(-.0007)]/!3
=0.7071 + .08246 + [(1.4)(.4)(-.0057)]/2 +[(1.4)(.4)(-.6)(-.0007)]/6
=0.7071 +.08246 -.001596 +.0000392
= .7880032
C Program:
#include<stdio.h>
#include<math.h>
int fact(int);
void main()
{
float arr[10][11],x,h,p,y,px=1;
int i,j,n,ch=30;
printf("\nEnter the number of data:");
scanf("%d",&n);
printf("\nEnter the data");
for(i=0;i<n;i++)
{ printf("X%d=",i+1);
scanf("%f",&arr[i][0]);
printf("Y%d=",i+1);
scanf("%f",&arr[i][1]);
}
//Forming difference table.
for(j=2;j<=n;j++)
for(i=0;i<n-1;i++)
arr[i][j]=arr[i+1][j-1]-arr[i][j-1];
//Printing table
printf("\nDifference table is:-");
printf("\n\tx\tY");
for(i=0;i<=n-2;i++)
printf("\t%c^%dY",ch,i+1);
for(i=0;i<n;i++)
{printf("\n");
for(j=0;j<n+1-i;j++)
{printf("\t%.4f",arr[i][j]);
}
}
//Take the value of x for f(x)
printf("\nEnter the value x for function f(x):");
scanf("%f",&x);
//Calculate the value of f(x) for x
h=arr[1][0]-arr[0][0];
p=(x-arr[0][0])/h;
y=arr[0][1];
for(i=1;i<n;i++)
{ px=px*(p-(i-1));
y=y+(arr[0][i+1]*px)/fact(i);
}
printf("\nthe value of function at x=%f is %f",x,y);
}
int fact(int n)
{ int i,f=1;
for(i=1;i<=n;i++)
f=f*i;
return f;
}
Output:
Enter the number of data:4
Enter the data
X1=45
Y1=.7071
X2=50
Y2=.7660
X3=55
Y3=.8192
X4=60
Y4=.8660
Difference table is:-
x Y ^1Y ^2Y ^3Y
45.0000 0.7071 0.0589 -0.0057 -0.0007
50.0000 0.7660 0.0532 -0.0064
55.0000 0.8192 0.0468
60.0000 0.8660
Enter the value x for function f(x):52
the value of function at x=52.000000 is 0.788003
No comments:
Post a Comment