/***************** Newtons interpolation **************/
#include<iostream.h>
#include<conio.h>
int main()
{
int n,i,j;
float x[10],f[10],a,sum=0,mult;
clrscr();
cout<<"No of sample points ? ";
cin>>n;
cout<<"\nAll x with corresponding f(x) ";
for(i=0;i<n;i++)
cin>>x[i]>>f[i];
cout<<"\nEnter x for calculation ";
cin>>a;
for(j=0;j<n-1;j++)
{
for(i=n-1;i>j;i--)
f[i]=(f[i]-f[i-1])/(x[i]-x[i-j-1]);
}
for(i=n-1;i>=0;i--)
{
mult=1;
for(j=0;j<i;j++)
mult*=(a-x[j]);
mult*=f[j];
sum+=mult;
}
cout<<"The result is: "<<sum;
getch();
return 0;
}
C C++ CODE for Newton's interpolation
Subscribe to:
Post Comments
(
Atom
)
can help me please?
ReplyDeleteto create a code for newton,
like this code, but can visible the polynomial first, then the result
i had try to modif this code, but still cannot get the code to visible the polynomial.
thank's
hansen