优化设计作业及程序.docx

优化设计程序及作业 1进退法求搜索区间程序: fun cti on hu=hu nt(x1,h) %定义函数为hunt,x1为初始值,h为步长 f=@(x)xA2-7*x+10; f1=f(x1);x2=x1+h; f2=f(x2); if f1f2 h=-h; x3=x1;f3二f(x3); x1= x2;f1=(x1); x2=x3;f2=f(x2); end x3=x2+h;f3=f(x3); while f3f2 h=h; x仁 x2;f1=f(x1); x2=x3;f2=f(x2); x3=x2+h;f3=f(x3); end display^ 所求区间) a=x1,b=x3 end 在命令窗口运行hunt(0,0.1 ),得搜索区间[3.4,3.6] 2黄金分割法求极值 fun cti on g=gold(a,b,j) %a,b为搜索区间,j为精度 f=@(x)xA2-7*x+10; k=0.6180339887; x1=a+(1-k)*(b-a); x2=a+k*(b-a); while abs(a-b)j f1=f(x1); f2=f(x2); if f1f2 b=x2;x2=x1; x1= a+(1-k)*(b-a); else a=x1; x1=x2; x2=a+k*(b-a); end end display^所求最优解) x=(a+b)/2 display(

文档评论(0)

1亿VIP精品文档

相关文档