///Bismillahir Rahmanir Rahim
///Author:Tanvir Ahmmad
///CSE,Islamic University,Bangladesh
///Dept.CSE,IU,Bangladesh
#include<iostream>
using namespace std;
typedef int in;
typedef double db;
int main()
{
in n,fin;
cout<<"Enter number of data point: ";
cin>>n;
in arr_x[n+3],arr_y[n+3];
cout<<"Input these "<<n<<" points:"<<endl;
for(in i=1; i<=n; i++) cin>>arr_x[i]>>arr_y[i];
cout<<"After given values : "<<endl;
for(in i=1; i<=n; i++)
cout<<"x["<<i<<"] = "<<arr_x[i]<<" "<<"y["<<i<<"] = "<<arr_y[i]<<endl;
cout<<"Enter interpolation point: ";
cin>>fin;
db ans=0;
for(in i=1; i<=n; i++)
{
db up=arr_y[i],down=1;
for(in j=1; j<=n; j++)
{
if(j==i) continue;
else up*=(fin-arr_x[j]),down*=(arr_x[i]-arr_x[j]);;
}
ans+=(up/down);
}
cout<<"Interpolated value of "<<fin<<" is "<<ans<<endl;
return 0;
}
///Alhamdulillah
Comments
Post a Comment