⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 insert_list.txt

📁 By the proof of Lemma 2 of Section 5.2, this accomplished as follows:
💻 TXT
字号:
# include <iostream>
# include <iomanip>
# include <cmath>
# include <fstream>
using namespace std;
class insert_list{
private:
	double **f;
	double *x;
	int N;
public:
    insert_list();
    ~insert_list(); 
	void cal_list();
	void cal_value();
};

insert_list::insert_list()
{
int i,j;
cout<<"input the number of the node:";
cin>>N;
x=new double [N+1];
f=new double*[N+1];
for(i=0;i<=N;i++)
f[i]=new double[i+1];
for(i=0;i<=N;i++)
   for(j=0;j<=i;j++)
	   f[i][j]=0;
ifstream in("e:\\numerical analysis\\insert_list\\data.txt");
for(i=0;i<=N;i++)
  in>>x[i]>>f[i][0];
in.close();
}
insert_list::~insert_list()
{
 for(int i=0;i<=N;i++)
  delete []f[i];
	delete []f;
	delete []x;
}
void insert_list::cal_list()
{
int i,j;
	for(i=1;i<=N;i++)
      for(j=1;j<=i;j++)
	  {
	    f[i][j]=(f[i][j-1]-f[i-1][j-1])/(x[i]-x[i-j]);
	  }
	  cout.setf(ios::fixed);
	  cout<<setprecision(6);
    for(i=0;i<=N;i++)
	{
		for(j=0;j<=i;j++)
		cout<<f[i][j]<<" ";
	  cout<<endl;
	}
}
void insert_list::cal_value()
{   
	double x0,y=f[0][0],temp;
	int i,j;
	cout<<"input the insert node:";
	cin>>x0;
	for(i=1;i<=N;i++)
	{
		temp=1;
		for(j=0;j<i;j++) 
	      temp=(x0-x[j])*temp;
	temp=f[i][i]*temp;
	y=y+temp;
	}
	cout<<y<<endl;
}


void main()
{
	insert_list a;
	a.cal_list();
	a.cal_value();
}




⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -