ga_f33.m

来自「其中提到遺傳學的程式碼與應用提供給次淚相向的研究者參考下載」· M 代码 · 共 75 行

M
75
字号
function PI=GA_f33(x)
% Fitness max. function evaluation of Example 3-3
% GA_ex33.m file
% [Kp Ki Kd] values for a PID control system

% PenChen Chou, 7-8-2001

global MIN_offset MUL_factor ROBUST Kp Ki Kd K a1 a2

Kp=GA_round4dp(x(1));
Ki=GA_round4dp(x(2));
Kd=GA_round4dp(x(3));
PI=0;

if ROBUST==0
    K=10;a1=3;a2=2;Err_scale=2;
    sim('ex33_pid',[0 4]); % see [tout and yout]
    I=find(tout>1.2); PI=sum(abs(100*(1-yout(I))));
    if max(yout)>1.15; PI=PI+500; end;
else    
Err_scale=1;    
% Round #1
K =12.5+7.5*(rand-0.5)*2;
a1=3.75+2.25*(rand-0.5)*2;
a2=2.50+1.5*(rand-0.5)*2;
sim('ex33_pid',[0 4]); % see [tout and yout]
I=find(tout>1.2); PI=sum(abs(100*(1-yout(I))));
if max(yout)>1.15
    PI=PI+500;
end;    
% Round #2
K =10;
a1=3;
a2=2;
sim('ex33_pid',[0 4]); % see [tout and yout]
I=find(tout>1.2); PI=PI+10*sum(abs(100*(1-yout(I))));
if max(yout)>1.15
    PI=PI+500;
end;    
% Round #3
K =12.5+7.5*(rand-0.5)*2;
a1=3.75+2.25*(rand-0.5)*2;
a2=2.50+1.5*(rand-0.5)*2;
sim('ex33_pid',[0 4]); % see [tout and yout]
I=find(tout>1.2); PI=PI+sum(abs(100*(1-yout(I))));
if max(yout)>1.15
    PI=PI+500;
end;    
% Round #4
K =20;
a1=6;
a2=4;
sim('ex33_pid',[0 4]); % see [tout and yout]
I=find(tout>1.2); PI=PI+sum(abs(100*(1-yout(I))));
if max(yout)>1.15
    PI=PI+500;
end;    
% Round #5
K =5;
a1=1.5;
a2=1;
sim('ex33_pid',[0 4]); % see [tout and yout]
I=find(tout>1.2); PI=PI+sum(abs(100*(1-yout(I))));
if max(yout)>1.15
    PI=PI+500;
end;    
end; % End of ROBUST check

PI=Err_scale*PI;
if MIN_offset~=0
    if PI>=MIN_offset, PI=MIN_offset-10; end;
    PI=MIN_offset-PI;
end;    
PI=MUL_factor*PI;
fprintf('>');

⌨️ 快捷键说明

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