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

📄 neville插值.txt

📁 数值分析程序
💻 TXT
字号:
#include <iostream.h>

void Neville(int n,double *x,double *y)
{
	int i,j;
	double *matrix;
	double _x;

	matrix=new double[n*n];
	for(i=0;i<n;i++)
		matrix[i*n]=y[i];

	cout<<"\nPlease input the inserted x:"<<endl;
	cin>>_x;

	for(i=1;i<n;i++)
		for(j=1;j<n&&i>=j;j++)
			matrix[i*n+j]=((_x-x[i])*matrix[(i-1)*n+j-1]-(_x-x[i-j])*matrix[i*n+j-1])/(x[i-j]-x[i]);
	
	cout<<"\nThe matrix is:"<<endl;
	for(i=0;i<n;i++)
		for(j=0;j<n&&i>=j;j++)
		{
			cout<<matrix[i*n+j]<<' '; 
			if(j==i) cout<<endl;
		}

	cout<<"\nThe result is: "<<matrix[(n-1)*n+n-1]<<endl;

	delete[] matrix;
}

void main()
{
	int i,n;
	double *x,*y;
	
	cout<<"Please input the sum of datas:"<<endl;
	cin>>n;

	x=new double[n];
	y=new double[n];

	cout<<"\nPlease input the Array x:"<<endl;
	for(i=0;i<n;i++)
		cin>>x[i];

	cout<<"\nPlease input the Array y:"<<endl;
	for(i=0;i<n;i++)
		cin>>y[i];
	
	Neville(n,x,y);

	delete[] x;
	delete[] y;
}

⌨️ 快捷键说明

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