《matlab黄金分割法求解.doc》由会员分享,可在线阅读,更多相关《matlab黄金分割法求解.doc(6页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
1、Four short words sum up what has lifted most successful individuals above the crowd: a little bit more.-author-datematlab黄金分割法求解4100105240 赵增建 10机本2班第4次作业 用matlab求解f(t)=(t2-1)2+(t-1)2+3 -10,10最小植(黄金分割法)。x为最优的t值,minf为最优的函数值,f为函数,t为函数f的变量,a,b为下单峰区间a,b,eps为精确度,M函数文件:function x,minf = minHJ(f,a,b,eps)fo
2、rmat long;if nargin = 3 eps = 1.0e-6;Endl = a + 0.382*(b-a);u = a + 0.618*(b-a);a=-10k=1;tol = b-a;while toleps & k fu a = l; l = u; u = a + 0.618*(b - a); else b = u; u = l; l = a + 0.382*(b-a); end k = k+1; tol = abs(b - a);endif k = 100000 disp(找不到最小值!); x= NaN; minf = NaN; return;endx= (a+b)/2;minf = subs(f, findsym(f),x);format short;窗口M文件调用: syms t f=(t.2-1).2+(t-1).2+3f =(t2-1)2+(t-1)2+3 x,minf = minHJ(f,-10,10,0.000001)a = -10x= 1.0000minf = 3.0000-