All Programs are Written and Compiled in Dev C++. So, it may generate some error in case of other compilers and may need some modifications in program. Download Dev C++

Thursday 9 April 2015

Interpolation using Newton's Divided Difference Formula (For Unequal Intervals)


#include<iostream>
using namespace std;
int main()
{
int x[10],y[10],p[10];
int i,j=1,k,n,t,y1,f=0;
cout<<"Enter No of Values in table: ";
cin>>n;
cout<<"Enter X and Corresponding Y\n";
cout<<"X   Y\n";
for(i=1;i<=n;i++)
cin>>x[i]>>y[i];
y1=y[1];
cout<<"Enter X for which f(x) is to be calculated: ";
cin>>k;

do
{
for(i=1;i<=n-1;i++)
{
p[i]=((y[i+1]-y[i])/(x[i+j]-x[i]));
y[i]=p[i];
}
t=1;
for(i=1;i<=j;i++)
t*=(k-x[i]);
f+=(y[1]*t);
n--;j++;
}while(n!=1);
f+=y1;
cout<<"\nFor X="<<k<<"\tCorresponding Y="<<f;
}

No comments:

Post a Comment