复合形法 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:4xceq=xceq+x0(:,i);endxceq=xceq/4;x0=xh;while(1)%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%最外层 if max(xh(:,4)—xceq)〈1e—5 xout=xh(:,4); break; endwhile(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;%约束函数1gx=subs(g,{x1,x2},xc); if gx〈=0&xc(1)>=0&xc(2)>=0;%推断xc在可行域内 break; x0=rand(2,4); endendwhile(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