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

📄 danchunxin.m

📁 基于单纯形无约束方法的PID参数整定。在myfun.m中输入目标函数和控制对象的传递函数
💻 M
字号:
function [fx,fy,iter,out,u_con] = DanchunXin(Init,dim,N,U,Y,R,E,rou)
if size(Init) ~= [dim,dim+1]
    error('error input length of parament Init!');
end
%initialization
alp = 1;
gamma = 2;
beta = 0.5;
%
Fval = zeros(1,dim+1);
Point = Init;%输入4个点
iter = 0;
while 1
  iter = iter+1;  
for m=1:dim+1
    Fval(m) = myfun(U,Y,R,E,N,Point(:,m),rou);
end

maxIndex = find(Fval==max(Fval));
maxp = Point(:,maxIndex);
minp = Point(:,find(Fval==min(Fval)));
subfval = [Fval(1:maxIndex-1),Fval(maxIndex+1:dim+1)];
subp = Point(:,find(subfval==max(subfval)));
FsubVal = myfun(U,Y,R,E,N,subp,rou);
%center
centp = (sum(Point')'-maxp)./dim;
FcentVal = myfun(U,Y,R,E,N,centp,rou);
%reflection
new2p = centp+alp*(centp - maxp);
Fnew2Val = myfun(U,Y,R,E,N,new2p,rou);
%step4
if Fnew2Val < FsubVal
    %expend
    new3p = centp + gamma*(new2p - centp);
    Fnew3Val = myfun(U,Y,R,E,N,new3p,rou);
   %step5
    if Fnew3Val<Fnew2Val
        %maxp = new3p;
        Point(:,maxIndex) = new3p;
    else
        %maxp = new2p;
        Point(:,maxIndex) = new2p;
    end
elseif and(myfun(U,Y,R,E,N,minp,rou)<=Fnew2Val,Fnew2Val<=FsubVal)
       %maxp = new2p;
       Point(:,maxIndex) = new2p;
elseif Fnew2Val>FsubVal
    %compress
    FnewpVal = min(myfun(U,Y,R,E,N,maxp,rou),Fnew2Val);
    if FnewpVal == Fnew2Val
        xh = new2p;
    else
        xh = maxp;
    end
    new4p = centp+beta*(xh - centp);
    Fnew4Val = myfun(U,Y,R,E,N,new4p,rou);
    %step6
    if Fnew4Val<=myfun(U,Y,R,E,N,xh,rou)
        %maxp = new4p;
        Point(:,maxIndex) = new4p;
    else
        %condense
        for m = 1:dim+1
            Point(:,m) = Point(:,m)+0.5*(minp-Point(:,m));
        end
    end
end
    %step7
        if converge(Point, centp,U,Y,R,E,N,rou)<eps*10^10
            break;
        else
            continue;
        end
end

fx = minp;
[fy,out,u_con] = myfun(U,Y,R,E,N,minp,rou);
   
   
            
            
            
            
            
            
            
            
            
            
            
            
            
            
function  sumf = converge(Point, centp,U,Y,R,E,N,rou)
Psize = size(Point);
dim = Psize(1);
%fval = zeros(1,dim+1);
fcentpVal = myfun(U,Y,R,E,N,centp,rou);
sumf = 0;
for m = 1:dim+1
    %fval(m) = myfun(Point(:,m));
    sumf = sumf+(myfun(U,Y,R,E,N,Point(:,m),rou) - fcentpVal)^2;
end
sumf = (sumf/(dim+1))^0.5;


    
    

⌨️ 快捷键说明

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