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

📄 newton.c

📁 牛顿插值公式:构造插值函数空间的基函数得到的多项式逼近的方法——牛顿插值法。用于多项式插值逼近。
💻 C
字号:
#include<stdio.h>
void main()
{
	float x[100],f[100],m[100][100];
	float y,N,P,Q;
	int i,j,k;
	printf("Please type in the number of the sum of the crunodes:");
	scanf("%d",&k);
	printf("Please type in the values of the crunodes in order:\n");
	for(i=0;i<k;i++)
		scanf("%f",&x[i]);
	printf("Please type in the values of the function values in order:\n");
	for(i=0;i<k;i++)
		scanf("%f",&f[i]);
	printf("Please put in the value that you want to get:");
	scanf("%f",&y);
	for(i=0;i<k;i++)
		for(j=0;j<k;j++)
		{
			if(i==0)
				m[i][j]=f[j];
			else
				m[i][j]=(m[i-1][j+1]-m[i-1][j])/(x[i+j]-x[j]);
		};

	printf("Nk(x)=");

	for(i=0;i<k;i++)
	{
		printf("%f",m[i][0]);
		if(i==0)
		{
			printf("+");
			continue;
		}
		else if(i==k-1)
			break;
		else
			for(j=0;j<i;j++)
				printf("(x-%f)",x[i-1]);
			printf("+");
	};
	
printf("\n");

	for(i=0,N=0;i<k;i++)
	{
		if(i==0)
			P=m[0][0];
		else
		{
			for(j=0,Q=1;j<i;j++)
				Q=(y-x[j])*Q;
			P=m[i][0]*Q;
		}
		N=N+P;
	};
	printf("N(%f)=%f",y,N);
}

⌨️ 快捷键说明

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