二分法求解,运行出错,求指导!
#include<stdio.h>
#include<math.h>
int main()
{
float fun(float ,float ,float );
float x1,x2,x3,f1,f2,f3;
printf("输入近似根区间:\n");
scanf("%f%f",&x1,&x2);
x3=fun(x1,x2,x3);
printf("近似根为%f\n",x3);
return 0;
}
float fun(float x1,float x2,float x3)
{
float f1,f2,f3;
f1=2*x1*x1*x1-4*x1*x1+3*x1-6;
f2=2*x2*x2*x2-4*x2*x2+3*x2-6;
while(f1*f2<=0&&fabs(f3)>=1e-6)
{
x3=(x1+x2)/2;
f3=2*x3*x3*x3-4*x3*x3+3*x3-6;
if(f1*f3<0)
{
x2=x3;
f2=f3;
}
else
{
x1=x3;
f1=f3;
}
}
return x3;
}