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

📄 newtoninterpolateexperiment.cpp

📁 这是牛顿插值的算法…… 是用于数值计算的 是很不错的 大家可以借鉴一下
💻 CPP
字号:
// NewtonInterpolateExperiment.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "NewtonInterpolateExperiment.h"
#include "NewtonInterpolate.h"
#include <afxtempl.h>

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// The one and only application object

CWinApp theApp;

using namespace std;

int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
	int nRetCode = 0;

	// initialize MFC and print and error on failure
	if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
	{
		// TODO: change error code to suit your needs
		cerr << _T("Fatal Error: MFC initialization failed") << endl;
		nRetCode = 1;
	}
	else
	{
		// TODO: code your application's behavior here.
		
/*		double InterpolateNodeX[6] = {0.40, 0.55, 0.65, 0.80, 0.90, 1.05};
		double InterpolateNodeY[6] = {0.41075, 0.57815, 0.69675,0.88811,1.02652, 1.25382};

		double x = 0.596, y;
		NewtonInterpolate a(5, InterpolateNodeX, InterpolateNodeY);
		y = a.Evaluation(x);
		printf("%f\n", y);
		printf("\n", y);


		NewtonInterpolate b;
		
		for(int i = 0; i<6; i++)
		{
			b.AddNode(1, *(InterpolateNodeX+i), InterpolateNodeY+i);
			y = b.Evaluation(x);
			printf("%d次多项式插值=%f\n",i,y);
		}
	

		int n = 5;
		int degree[] = {1, 1, 1, 1, 1, 1};
		double X[6] = {0.40, 0.55, 0.65, 0.80, 0.90, 1.05};
		double *p = InterpolateNodeY;
		double *Y[6] = {p, p+1, p+2, p+3, p+4, p+5};
		NewtonInterpolate c(n, degree, X, Y);
		y = c.Evaluation(x);
		printf("%f\n", y);


*/
		/*
		p(1)=2, p'(1)= 3
		p(2)=6, p'(2)= 7, p"(2) = 8
		p(x) = 2  +3(x-1)  +(x-1)^2  +2(x-1)^2*(x-2)  -3(x-1)^2*(x-2)^2
		系数为{2, 3, 1, 2, -1};
		*/
	/*	double x = 0.596, y;
		int n = 1;
		int degree[] = {2, 3};
		double X[6] = {1, 2};
		double p[] = {2, 3, 6, 7, 8};
		double *Y[2] = {p, p+2};
		NewtonInterpolate c(n, degree, X, Y);
		y = c.Evaluation(x);
		c.PrintPolynomial();
		printf("c=%f\n", y);	//0.128621
*/
		double x = 5, y;
		int n;
		int degree[] = {3, 2, 1, 2};
		double X[6] = {1, 2, 6,7};
		double p[] = {3, 4, 8, 2, 4, 4, 2, 5};
		double *Y[4] = {p, p+3, p+5, p+6};

		n= 2;
		NewtonInterpolate c(n, degree, X, Y);
		y = c.Evaluation(x);
		c.PrintPolynomial();
		printf("c=%f\n\n", y);	
	
		n=3;
		c.AddNode(degree[3], X[3], Y[3]);
		y = c.Evaluation(x);
		c.PrintPolynomial();
		printf("c=%f\n", y);	

	}

	return nRetCode;
}

⌨️ 快捷键说明

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