在学《计算方法》这门课程,跟随课堂进度,用C++代码实现课本中讲述的几种插值算法,权当练习。
首先我们定义Point类
class Point
{
public:
double x;
double y;
};
对于每一个算法类,为了计算算法计算次数,所有都定义了以下成员变量及方法:
private:
int m_calCount;
void ZeroCalCount()
{
m_calCount = 0;
}
void CalCountAdd()
{
m_calCount++;
}
public:
int GetCalCount()
{
return m_calCount;
}
在之后的算法代码中不予呈现
作为测试插值效果,main函数中代码如下(不断更新):
(测试数据目前为f(x) = lnx 1-5 共五组数据)
int _tmain(int argc, _TCHAR* argv[])
{
Lagrange lag;
Newton newt;
int count;
double x;
cout << "Please input the number of points" << endl;
cin >> count;
Point *pt = new Point[count];
for (int i = 0; i < count; i+