解非线性方程y=x^3 +4*x^2-10在区间[1,2]的根,精确到小数点后第三位
需要自己确定等价方程
#include <iostream>
#define WUCHA 0.0005
using namespace std;
double hanshu(double x) {//函数
return 0.5 * sqrt((10 - x * x * x));
}
int main()
{
double x = 1.5;
double xx = 10000000;
int count = 0;
while (abs(x - xx) > WUCHA) {
xx = x;
x=hanshu(x);
count++;
}
cout << "结果:" << x <<endl;
cout << "迭代次数:" << count;
}