关于黄金分割法求极小值问题,运行出了很多错,求大神知道
#include<stdio.h>#include<stdlib.h>
#include<math.h>
#define beita 0.618
#define e 0.00001
int main()
{
float x,a=0,b=10,t1,t2,f0,f1,f2;
t2=a+beita*(b-a);
f2=t2*t2-10*t2+36;
t1=a+b-t2;
f1=t1*t1-10*t1+36;
while (abs(t1-t2)>e)
{
if (f1<=f2)
b=t2;
t2=t1;
f2=f1;
t1=a+b-t2;
f1=t1*t1-10*t1+36;
else
a=t1;
t1=t2;
f1=f2;
t2=a+beita*(b-a;
f2=t2*t2-10*t2+36;
}
t0=0.5*(t1+t2);
f=t0*t0-10*t0+36;
printf("The answer is %f\n",f);
system("pause");
}