/*
*方程:2*x*x*x - 4*x*x + 3*x - 6 = 0;
*/
#include <iostream>
#include <cmath>
using namespace std;
double f(double x);
int main(void){
double x1 = -10, x2 = 10, x;
while(fabs(x1-x2)>=1e-6){
x = (x1+x2)/2;
if(f(x)*f(x1)<0){
x2 = x;
}else{
x1 = x;
}
}
cout << x1 << endl;
}
double f(double x){
return 2*x*x*x - 4*x*x + 3*x - 6;
}
二分法求方程根
最新推荐文章于 2022-08-13 21:11:18 发布