/********** Lagrange's interpolation ***************/
#include<iostream.h>
#include<conio.h>
int main()
{
int n,i,j;
float mult,sum=0,x[10],f[10],a;
clrscr();
cout<<"Enter no of sample points ? ";
cin>>n;
cout<<"Enter all values of x and corresponding funtional value: "<<endl;
for(i=0;i<n;i++)
cin>>x[i]>>f[i];
cout<<"\nEnter your x for calculation : ";
cin>>a;
for(i=0;i<=n-1;i++)
{
mult=1;
for(j=0;j<=n-1;j++)
{
if(j!=i)
mult*=(a-x[j])/(x[i]-x[j]);
}
sum+=mult*f[i];
}
cout<<"\nThe estimated value of f(x) = "<<sum;
getch();
return 0;
}
(Ganesh Tiwari) gt_ebuddy's Blog - Code snippets, technical articles, tips on computing and programming...
C C++ CODE: Lagrange's interpolation
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment
Your Comment and Question will help to make this blog better...