📄 快速弦截法.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 + -