📄 lagrange.cpp
字号:
#include <iostream.h>
#include <math.h>
#include <iomanip.h>
double Lagrange(double x[],double y[],int n,double xx)
{
double yy=0.0;
for(int k=0;k<n;k++)
{
double temp=1.0;
for(int j=0;j<n;j++)
{
if(j==k)
continue;
temp*=(xx-x[j])/(x[k]-x[j]);
}
yy+=temp*y[k];
}
return yy;
}
void main()
{
double x=115;
/* double y=Simpson(100,10,121,11,144,12,x);
cout<<"the square root of the "<<x<<": "<<y<<endl;*/
//x=115;
double x0[3]={100,121,144};
double y0[3]={10,11,12};
double y=Lagrange(x0,y0,3,x);
cout<<"the square root of the "<<x<<": "<<y<<endl;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -