复合形法 matlab程序编译命令流
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
复合形法 matlab程序编译命令流
clear all;close all;
a=1.3;xceq=zeros(2,1);%迭代中止值
tmp=zeros(2,1);%临时变量
syms x1 x2 gx;
x0=zeros(2,4);xh=zeros(2,4);
x0(:,1)=[0.25 0.5]';x0(:,2)=[0 1]';
x0(:,3)=[1 0]';x0(:,4)=[0.48 0.55]';
for i=1:4
xceq=xceq+x0(:,i);
end
xceq=xceq/4;
x0=xh;
while(1)%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%最外层
if max(xh(:,4)-xceq)<1e-5
xout=xh(:,4);
break;
end
while(1)
xh=compare_int(xh);%找出最好点--最差点(1)
xc=zhao_xing_xin(xh);%找形心(2)
f=x1^2+2*x2^2-2*x1^2*x2^2;%原函数
g=x1^2+x2^2+x1*x2-2;%约束函数1
gx=subs(g,{x1,x2},xc);
if gx<=0&xc(1)>=0&xc(2)>=0;%判断xc在可行域内
break;
x0=rand(2,4);
end
end
while(1)%%%%%%%66666666666666666666666666666666666666666
while(1)
xr=xc+a*(xc-xh(1));%求反射点
%%%循环直至xr为可行点%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
gx=subs(g,{x1,x2},xr);
if gx<=0&xr(1)>=0&xr(2)>=0
break;
end
a=a/2;
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
fxr=subs(f,{x1,x2},xr);
fxh=subs(f,{x1,x2},xh(:,1)); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%(5)%%%%%%%%%%
while fxr xh(:,1)=xr; xh=compare_int(xh);%找出最好点--最差点%%%%%%%%%%%%迭代中止值%%%%%%%%% for i=1:4 xceq=xceq+xh(:,i); end xceq=xceq/4; if(max(xh(:,4)-xceq)<1e-5) xout=xh(:,4); break; end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% xc=zhao_xing_xin(xh);%找形心 gx=subs(g,{x1,x2},xc); if gx<=0&xc(1)>=0&xc(2)>=0; break; x0=rand(2,4); end end a=a/2; if a<1e-5 break; end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%(5)%%%%%%%%%%%% end%%%%%%%%%%%%%%%%%666666666666666666666666666666666666 tmp=xh(:,1);xh(:,1)=xh(:,2);xh(:,2)=tmp;%%%%将次差点代替最差点end %找形心 function xc=zhao_xing_xin(xh) xc=zeros(2,1); for i=2:4 xc=xc+xh(:,i); end xc=xc/(i-1); function xh=compare_int(x0) %x0(:,1)=[0.25 0.5]';x0(:,2)=[0 1]'; %x0(:,3)=[1 0]';x0(:,4)=[0.48 0.55]'; %以矩阵形式输入初始四个顶点x0(2,4) %%找出最好点--最差点 n=2;k=1; syms x1 x2; f=x1^2+2*x2^2-2*x1^2*x2^2;%原函数 for i=1:4 f0(i)=subs(f,{x1,x2},x0(:,i)); end for i=1:4 if a a=f0(i); xh(:,1)=x0(:,i); end end b=0; for i=1:4 if b xh(:,2)=x0(:,i); end end c=0; for i=1:4 if c xh(:,3)=x0(:,i); end end d=0; for i=1:4 if d xh(:,4)=x0(:,i); end end