解非线性方程y=x^3 +4*x^2-10在区间[1,2]的根,精确到小数点后第三位
严格按照科学出版社数值计算方法定义
#include <iostream>
using namespace std;
#define WUCHA 0.0005//误差
double hanshu(double x) {//函数
return x * x * x + x * x * 4.0 - 10.0;
}
int main()
{
double a = 1;
double b = 2;
double midd;
int count = 1;
while ((b - a)/2 > WUCHA) {
midd = (a + b) / 2;
if (hanshu(midd) > 0.0) {
b=midd;
}
else {
a=midd;
}
count++;
}
cout << "结果:" << (a+b)/2 << endl;
cout << "运算次数:" << count;
return 0;
}
}
来源:CSDN
作者:菜虚困爱菜籽
链接:https://blog.csdn.net/weixin_43625164/article/details/104613250