精选优质文档-倾情为你奉上以f(x)=*x+2*x为例黄金分割#include #define e 0.001/收敛精度main()float a,b,x1,x2,y1,y2;float minx,miny;x1=-3;x2=5;/x1,x2初始化a=x1;b=x2;/a1,a2初始化do x1=a+0.382*(b-a); x2=a+0.618*(b-a);y1=x1*x1+2*x1;y2=x2*x2+2*x2; if(y1y2) a=x1; else b=x2; while(b-a)e);/两个数值小于收敛精度e时终止minx=(x1+x2)/2;/取两数值平均值miny=minx*minx+2*minx;printf(The minx is %f and the miny is %f.n,minx,miny);/极小值二次插值法#