从答案看,方程解在(5,6)中,从此区间进行二分
代码(伪):
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int main(){
printf("5.705085930");
return 0;
}
代码:
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
double f(double x)
{
return x*x*x+-5*x*x+10*x-80;
}
double search(double a,double b)
{
while(b-a>1e-11)
{
double mid=(a+b)/2.0;
if(f(mid)>0)b=mid;
else a=mid;
}
return a;
}
int main(){
printf("%.9lf",search(5.0,6.0));
return 0;
}