#include <iostream>
using namespace std;
double laglang(double t,double *x,double *y)
{
double r=0.0;
double temp=1.0;
for (int k=0;k<5;k++)
{
temp=1.0;
for (int j=0;j<5;j++)
{
if (j!=k)
{
temp*=(t-x[j])/(x[k]-x[j]);
}
}
r+=temp*y[k];
}
return r;
}
int main()
{
double T[5]={20.5,32.7,51.0,73.0,95.7};
double R[5]={765.0,826.0,873.0,942.0,1032.0};
double ans=0;
ans=laglang(60.0,T,R);
cout<<ans<<endl;
system("pause");
}
转载于:https://www.cnblogs.com/tiandsp/archive/2011/10/20/2219634.html