插值法之Lagrange插值
2013-07-16 22:15
218 查看
//Lagrange插值法
#include <iostream>
#include <fstream>
using namespace std;
class lagrange
{
private:
int i, j, n;
double mult, sum, z;
double* x, * y;
public:
void interpolation();
~lagrange()
{
delete[] x, y;
}
};
void main()
{
lagrange interp;
interp.interpolation();
}
void lagrange::interpolation()
{
ifstream fin ("lagrange.txt");
fin >> n;
x = new double
;
y = new double
;
for (i = 0; i < n; i++)
{
fin >> x[i] >> y[i];
}
fin.close();
cout << "\n输入需要插值的点:";
cin >> z;
sum = 0.0;
for (i = 0; i < n; i++)
{
mult = 1.0;
for (j = 0; j < n; j++)
{
if (j != i)
{
mult *= (z - x[j]) / (x[i] - x[j]);
}
}
sum += mult * y[i];
}
cout << "\n插补的值 = " << sum << endl;
}
#include <iostream>
#include <fstream>
using namespace std;
class lagrange
{
private:
int i, j, n;
double mult, sum, z;
double* x, * y;
public:
void interpolation();
~lagrange()
{
delete[] x, y;
}
};
void main()
{
lagrange interp;
interp.interpolation();
}
void lagrange::interpolation()
{
ifstream fin ("lagrange.txt");
fin >> n;
x = new double
;
y = new double
;
for (i = 0; i < n; i++)
{
fin >> x[i] >> y[i];
}
fin.close();
cout << "\n输入需要插值的点:";
cin >> z;
sum = 0.0;
for (i = 0; i < n; i++)
{
mult = 1.0;
for (j = 0; j < n; j++)
{
if (j != i)
{
mult *= (z - x[j]) / (x[i] - x[j]);
}
}
sum += mult * y[i];
}
cout << "\n插补的值 = " << sum << endl;
}
相关文章推荐
- 拉格朗日插值法在数据分析中的应用——Python插值scimpy,lagrange
- Lagrange 插值
- Lagrange插值问题
- 数值分析中插值方法-Lagrange插值
- Java实现lagrange 插值法
- 【数值分析】插值法:拉格朗日插值、牛顿插值
- 使用Matlab进行图像的读写、显示和缩放(最近临插值和双线性内插值法)
- 拉格朗日(Lagrange)插值曲线
- Lagrange插值求解线性方程
- 拉格朗日(lagrange)插值及其MATLAB程序
- 利用lagrange插值法计算函数值
- 用C#实现的等距Lagrange插值代码
- 插值法之Language和基本插值多项式的C++代码实现
- 插值法(拉格朗日插值和牛顿插值)
- [转载]Lagrange插值方法
- 【数值分析】插值法:拉格朗日插值、牛顿插值
- 插值法:拉格朗日插值、牛顿插值
- 插值方法——Lagrange插值公式
- 拉格朗日(Lagrange)插值法(C语言)
- 拉格朗日(lagrange)插值计算