在用二分法求根时阀值的大小确定
有没有什么依据,我看书上的例子是输入的0.001是不是只能输入0.001
2010-10-05 16:26

2010-10-05 16:33
程序代码:#include<stdio.h>
#include<math.h>
void main()
{
float x0,x1,x2,fx0,fx1,fx2;
do
{
printf("Enter x1&x2:\n");
scanf("%f,%f",&x1,&x2);
fx1=x1*((2*x1-4)*x1+3)-6;
fx2=x2*((2*x2-4)*x2+3)-6;
}while(fx1*fx2>0);
do
{
x0=(x1+x2)/2;
fx0=x0*((2*x0-4)*x0+3)-6;
if((fx0*fx1)<0)
{
x2=x0;
fx2=fx0;
}
else
{
x1=x0;
fx1=fx0;
}
}while(fabs(fx0)>=1e-5);
printf("x=%6.2f\n",x0);
}路过!顺便给楼主段代码
2010-10-05 19:09