/********** 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;
}
C C++ CODE: Lagrange's interpolation
Subscribe to:
Post Comments
(
Atom
)
how to enter values in running code
ReplyDeleteany examples?
ReplyDelete