difvalue.cpp

来自「C++实现的数值分析源程序」· C++ 代码 · 共 35 行

CPP
35
字号
//梁霄 11/24/2005
#include"DifValue.h"
//牛顿法
double Newton::f(double x)
{
	return x*exp(x)-1;
}
double Newton::diff(double x)
{
	return (f(x+0.0001)-f(x))/0.0001;
}
void Newton::CommonNewton(double x0)
{
	cout<<"--------Newton Method--------"<<endl;

	for(int i=1;i<=10;i++)
	{
		x0-=f(x0)/diff(x0);
		cout<<"i="<<i<<'\t'<<"x="<<x0<<endl;
	}
}
//快速弦截法
void ChordCut::Chord(double x0,double x1)
{
	double xn;

	cout<<"--------Swift ChordCut Method--------"<<endl;
	for(int i=1;i<=10;i++)
	{
		xn=x1-f(x1)*(x1-x0)/(f(x1)-f(x0));
		x0=x1;
		x1=xn;
		cout<<"i="<<i<<'\t'<<"x="<<xn<<endl;
	}
}

⌨️ 快捷键说明

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