// lagrange.cpp: 主项目文件。// sin30o = 0.5; sin60o = sqrt(3)/2≈0.86603,求sin50o=? #include <stdafx.h>#include <iostream>using namespace std;double Lagrange(int n, double x_var, double *x, double *y);bool CheckValid(int n, double *x);int main( )...{ double x[ 2] = ...{ 30, 60}; double y[ 2] = ...{0.5, 0.86603}; double x_var = 50; double res = 0.0f; if(!CheckValid(1,x) )...{ cout <<"输入的插值节点的x值必须互异!"<<endl; } res = Lagrange( 1,x_var,x,y); //printf("the result is : %3.5f ",res); cout << "the result is :" << res ; getchar(); return 0;}/**//*检查当i!=j时是否有x[i] == x[j]的情况,如果有则不符合算法条件*/bool CheckValid(int n, double *x)...{ int i; int j; for(i = 0; i <= n ; i++)...{ for( j = 1; j<= n; j++)...{ if ( i == j)...{ continue; }else...{ if(x[i] == x[j]) return false; }//end of else }//end of if }// end of for(i) return true;}/**//* * n: 插值次(阶)数; * x_var:待求结果对应的x值; *数组*x,*y 为已知插值节点(xi,yi) */double Lagrange(int n, double x_var, double *x, double *y)...{ /**//* * Local variables definition */ int i; int j; double tempi = 0.0f; double tempj = 0.0f; for ( i = 0; i <= n; i++ )...{ tempj = 1.0f; for ( j = 0; j <= n; j++ )...{ if ( j == i)...{ continue; }else...{ tempj *= ( x_var - x[j])*1.0/( x[i] - x[j] ); } }/**//* end of for(j)*/ tempi += tempj * y[i]; }/**//* end of for(i) */ return tempi;}