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

📄 newton_cpp.cpp

📁 计算方法《牛顿差值》
💻 CPP
字号:
#include<iostream.h>
const int MAX=10;
struct point
{
	double x;
	double y;
}point[MAX];
void main()
{
	short i,j,n;
    double f[MAX][MAX],S,x=11.5,Nnx;
	cout<<"Please input the n:";
	cin>>n;
	if(n>MAX)
		cout<<"ERROR!"<<endl;
	else
		cout<<"Please input the point:"<<endl;
	for(i=0;i<=n;i++)
	{
		cout<<"point["<<i<<"]:";
		cout<<"x=";cin>>point[i].x;
		cout<<"y=";cin>>point[i].y;
	}
	for(i=0;i<=n;i++)
		f[i][0]=point[i].y;
	for(j=1;j<=n;j++)
	{
		for(i=j;i<=n;i++)
		{
			f[i][j]=(f[i][j-1]-f[i-1][j-1])/(point[i].x-point[i-j].x);
		}
	}
	cout<<"Please input x value:";
	cin>>x;
	for(i=1,Nnx=f[0][0];i<=n;i++)
	{
		for(j=0,S=1;j<=i-1;j++)
		{
			S=S*(x-point[j].x);
		}
		Nnx=Nnx+f[i][i]*S;
	}
	cout<<"Output the Nnx:"<<"Nnx="<<Nnx<<endl;
}


⌨️ 快捷键说明

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