求教高手帮忙,黄金分割法求最优解,这程序有什么错误?
#include<stdio.h>#include<math.h>
#define qq 0.61833988
void main()
{
float a,b,c,d,x1,x2,x3,x4,f1,f2,f3,f4,t;
printf("xishu:\n");
scanf("%f%f%f%f",&a,&b,&c,&d);
printf("fanwei and jingdu:\n");
scanf("%f%f%f",&x1,&x2,&t);
f1=a*x1*x1*x1+b*x1*x1+c*x1+d;
f2=a*x2*x2*x2+b*x2*x2+c*x2+d;
while(float ((fabs((f2-f1)/f1))<t))
{
x3=x1+qq*(x2-x1);
x4=x1+(1-qq)*(x2-x1);
f3=a*x3*x3*x3+b*x3*x3+c*x3+d;
f4=a*x4*x4*x4+b*x4*x4+c*x4+d;
if(f3>f4)
{
x2=x3;f2=f3;x3=x4;f3=f4;
}
else
{
x1=x4;f1=f4;x2=x3;f2=f3;
}
x4=x1+qq*(x1-x2);
}
printf("jie come:%f,%f\n",x3,f3);
}
在线等啊,谢谢了!!