Amazon Affiliate

Tuesday 17 April 2012

PROGRAM FOR NEWTON BACKWARD INTERPOLATION METHOD..

/program for newton backward interpolation formula





#include
#include
#include
#define maxn 100
#define order 4
void main()
{
float ax[maxn+1],ay[maxn+1],diff[maxn+1][order+1],nr=1,dr=1,x,p,h,yp;
int n,i,j,k;
clrscr();
cout<<"enter the value of n\n";
cin>>n;
cout<<"enter the values in form x,y\n";
for(i=1;i<=n;i++)
{cin>>ax[i]>>ay[i];}
cout<<"enter the value of x for which value of y is wanted\n";
cin>>x;
h=ax[2]-ax[1];
for(i=n;i>=1;i--)
{diff[i][1]=ay[i]-ay[i-1];}
for(j=2;j<=order;j++)
{
for(i=n;i>j;i--)
{diff[i][j]=diff[i][j-1]-diff[i-1][j-1];}
}
i=n;
p=(x-ax[i])/h;
yp=ay[i];
for(k=1;k<=order;k++)
{
nr*=p+k-1;
dr*=k;
yp+=(nr/dr)*diff[i][k];
}
cout<<"when x = "<<X<<" padding-top:2px;? width:700px; height:21px; y="<<yp;
getch();
}

No comments:

Post a Comment