首页 > 试题广场 >

为方程x^3 -x^2 -1=0 在x 0 =1.5 附近的

[问答题]

为方程x 3 -x 2 -1=0 在x 0 =1.5 附近的一个精确到4位小数的根,设将方程改写成,并建立相应的迭代公式.

# include <iostream>
# include <cmath>
using namespace std;
double f(double x) {
double f1,f2;
do{
f1=x*x*x-x*x-1;
f2=3*x*x+2*x;
x=x-f1/f2;
}while(fabs(x*x*x-x*x-1)>1e-5);
return x;
}
int main(){
printf("%.4lf\n", f(1.5));
return 0;
}
编辑于 2018-04-27 22:10:05 回复(0)