double fun(double x)
{//多项式
double a[]={2,-4,0,3}
double sum
int n=4
n--
sum=a[n]
while(--n >= 0)
sum=sum*x+a[n]
return sum
}
typedef double (*Function)(double)
double cal(Function f,double a,double b,double e)
{
double a1,a2,a3,t_a2,t
a1=aa3=ba2=(a+b)/2
while(1)
{
t=((f(a3)-f(a2))/(a3-a2)-(f(a2)-f(a1))/(a2-a1))/(a3-a1)
t_a2=((a1+a2)*t-(f(a2)-f(a1))/(a2-a1))/(2*t)
if(t_a2-a2 <e &&t_a2-a2 >-e)break
if(t_a2 >a2)a1=a2
else a3=a2
a2=t_a2
}
return f(t_a2)
}
void main()
{
printf("%lf\n",cal(fun,0,2,0.01))
void find(float start,float end,float &best){
float m=start
float n=0
float the_best=0
while(m<end)
{
n=(float)(m+(float)(20/m))
if(n<the_best)
the_best=n
m+=0.01
}
best=the_best
}
//start end分别代表初始点左右坐标,best是最终的最优解