⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 complex1.m

📁 复合形法matlab优化程序
💻 M
字号:
clc
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<fxh
    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

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -