用二分法求根的问题
请问区间那里应该怎么估算?#include <stdio.h>
#include <math.h>
#include <stdlib.h>
// declare function
double f(double x);
// defind function
double f(double x)
{
return (3.1415926(x*x*x-30*x*x+1000))/3;
}
int main()
{
double mid;
double e=0.000001
double a=0;
double b=
double y;
while (abs(a+b)>e)
{
mid=(a+b)/2;
y=f(a)*f(mid);
if (y<0)
b=mid;
else
a=mid;
}
printf("%lf \n",mid);
return 0;
}
[此贴子已经被作者于2017-3-7 13:22编辑过]