您好,欢迎访问三七文档
当前位置:首页 > 电子/通信 > 数据通信与网络 > 鲍威尔算法matlab程序-f
functionf=fun(x)f=10*(x(1)+x(2)-5)^2+(x(1)-x(2))^2;functionf=fx(x0,alpha,s)x1=x0+alpha*s;f=fun(x1);functionf=fsearch(x0,s)%利用进退法确定高低高区间alpha1=0;h=0.1;alpha2=alpha1+h;f1=fx(x0,alpha1,s);f2=fx(x0,alpha2,s);iff1f2alpha3=alpha2+h;f3=fx(x0,alpha3,s);whilef2f3alpha1=alpha2;alpha2=alpha3;alpha3=alpha3+h;f2=f3;f3=fx(x0,alpha3,s);endelseh=-h;v=alpha1;alpha1=alpha2;alpha2=v;v=f1;f1=f2;f2=v;alpha3=alpha2+h;f3=fx(x0,alpha3,s);whilef2f3alpha1=alpha2;alpha2=alpha3;alpha3=alpha3+h;f2=f3;f3=fx(x0,alpha3,s);endenda=min(alpha1,alpha3);b=max(alpha1,alpha3);%利用黄金分割点法求解alpha1=a+0.382*(b-a);alpha2=a+0.618*(b-a);f1=fx(x0,alpha1,s);f2=fx(x0,alpha2,s);whileabs(a-b)0.001iff1f2a=alpha1;alpha1=alpha2;f1=f2;alpha2=a+0.618*(b-a);f2=fx(x0,alpha2,s);elseb=alpha2;alpha2=alpha1;f2=f1;alpha1=a+0.382*(b-a);f1=fx(x0,alpha1,s);endendf=0.5*(a+b);clear%初始点x0=[0;0];%搜索方向e1=[1;0];e2=[0;1];G0=fun(x0);F0=G0;%第一次迭代%沿着e1alpha1=fsearch(x0,e1);x1=x0+alpha1*e1;F1=fun(x1);delta1=F0-F1;%沿着方向e2;alpha2=fsearch(x1,e2);x2=x1+alpha2*e2;F2=fun(x2);G2=F2;delta2=F1-F2;deltam=max(delta1,delta2);%映射点x3=2*x2-x0;G3=fun(x3);ifG3G0&(G0-2*G2+G3)*(G0-G2-deltam)^20.5*deltam*(G0-G3)^2s=x2-x0;%方向替换e1=e2;e2=s;%沿着方向s进行搜索alpha3=fsearch(x2,s);x3=x2+alpha2*s;x0=x3;elseifF2G3x0=x3;elsex0=x2;endEnd子文件JT,JH进退法程序代码�56555.function[minx,maxx]=minJT(f,x0,h0,eps)formatlong;ifnargin==3eps=1.0e-6;endx1=x0;k=0;h=h0;while1x4=x1+h;k=k+1;f4=subs(f,findsym(f),x4);f1=subs(f,findsym(f),x1);iff4f1x2=x1;x1=x4;f2=f1;f1=f4;h=2*h;elseifk==1h=-h;x2=x4;f2=f4;elsex3=x2;x2=x1;x1=x4;break;endendendminx=min(x1,x3);maxx=x1+x3-minx;formatshort;黄金分割法程序代码�56555.function[x,minf]=minHJ(f,a,b,eps)formatlong;ifnargin==3eps=1.0e-6;endl=a+0.382*(b-a);u=a+0.618*(b-a);k=1;tol=b-a;whiletoleps&&k100000fl=subs(f,findsym(f),l);fu=subs(f,findsym(f),u);ifflfua=l;l=u;u=a+0.618*(b-a);elseb=u;u=l;l=a+0.382*(b-a);endk=k+1;tol=abs(b-a);endifk==100000disp('ÕÒ²»μ½215?î208?¡214Oμ£¡);x=NaN;minf=NaN;return;endx=(a+b)/2;minf=subs(f,findsym(f),x);formatshort;
本文标题:鲍威尔算法matlab程序-f
链接地址:https://www.777doc.com/doc-4640765 .html