📄 newton _070460.cpp
字号:
#include<iostream.h>
#include<iomanip.h>
#include<math.h>
double newton(double z,double eps)
{ int i=0;
double x=0;
while(i<=1000000 && fabs(x-z)>=eps)
{
x=z;
z=x-((x*x*x/3.0)-x)/(x*x-1.0);
i++;
}
if(i>100000)
cout<<"次迭代格式不收敛!"<<endl;
else return z;
}
void main()
{
double y,eps;
int w;
cout<<"确定当X0在区间(-a,a)内取值,迭代序列收敛于根X=0时,尽可能大的a的值"<<endl;
cout<<"测试结果如下,观察即可知道尽可能大的a值为0.77:"<<endl;
double x=-0.8;
while (x<=0.8&&x>=-0.8)
{
cout<<"x0="<<setw(4)<<x<<":"<<setw(8)<<"x="<<newton(x,0.0000001)<<endl;
x+=0.01;
}
cout<<endl;
do{
cout<<"代入其它的初值为:"<<endl;
cin>>y;
cout<<"允许误差为: "<<endl;
cin>>eps;
cout<<"迭代求得的根:"<<newton(y,eps)<<endl<<endl;
cout<<"继续请按1,退出请按0"<<endl;
cin>>w;
}
while(w);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -