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

📄 快速弦截法.cpp

📁 计算方法中的五种算法: 二分法、简单迭代法、快速弦截法、龙贝格算法、弦截法。 附说明
💻 CPP
字号:
#include<iostream.h>
#include<math.h>

double f(double x)
{
	return x*x*x - 3*x - 1;
}

void KuaiSuXieJie(double x, double y, double e)
{
	cout<<'\t'<<"k\t"<<"x\t"<<"x前 - x后\n";
	double t1, t2, z;
	cout<<'\t'<<"0\t"<<x<<'\n';
	for(int k = 1; ; k++)
	{
		cout<<'\t'<<k<<'\t'<<y<<'\t'<<y-x<<'\n';
		if( fabs(y - x) < e )
		{
			cout<<"结果为:"<<y<<'\n';
			break;
		}
		else
		{
			t1 = f(x);
			t2 = f(y);
			z = y - (y - x) * t2 / (t2 - t1);
			x = y;
			y = z;
		}
	}
}

void main(void)
{
	double x, y, e;
	cout<<"输入初始值:";
	cin>>x;
	cout<<"输入另一个初始值:";
	cin>>y;
	cout<<"输入精度:";
	cin>>e;
	KuaiSuXieJie(x, y, e);
}

⌨️ 快捷键说明

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