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

📄 ga_ex38.m

📁 书籍代码:遗传演算法原理与应用_活用MATLAB(Source Code)
💻 M
字号:
% GA_ex38.m file
% Find scaling factors [Se Sde Su] of a 2nd order plant

% PenChen Chou, 7-15-2001

%**********************************************************/
%       User can modify the following in blocks
%**********************************************************/
global MIN_offset MUL_factor LOCUS x_data y_data Se Sde dSu
global MDL Emin Final_time

nn_flc=readfis('nn_flc');
MIN_offset=5e5; LOCUS=0; x_data=[]; y_data=[];
Final_time=55;
MUL_factor=1;
Emin=MIN_offset;
MDL='ex38s1';
%eval(MDL)
obj_fcn = 'GA_f38';	% Objective function
range = [1 0.1    0.0001
   20       10      0.1];	% Range of the input variables
range = [5 0.3 0.0005
         20 1  0.002];	% Range of the input variables
IC=[];elite=1;
gen_no=40;  popuSize=90;
gen_no=48;  popuSize=40;
%************************************************************
% calling GA 
tic
% function [popu, popu_real, fcn_value, upper, average,...
%   lower, BEST_popu, popuSize, gen_no, para]=GA_genetic(obj_fcn,...
%   range, IC, elite, gen_no, popuSize, bit_n, xover_rate,...
%   mutate_rate);
[popu, popu_real, fcn_value, upper, average, lower, ...
    BEST_popu, popuSize, gen_no, para] = GA_genetic(obj_fcn,...
    range, IC, elite, gen_no, popuSize);
t=toc/60;

fprintf('==>  Computation time is (%.2f) minutes.\n',t);            
            
% Plot the final results
Se=para(1);
Sde=para(2);
dSu=para(3);
Emin=2e6;
[T, X, Y]=sim(MDL,[0 140]);
in=Y(:,1); y=Y(:,2); STP=sum(Y(:,3)); 
err=Y(:,4); N=length(err); ERR=err(N);
if STP>0, ERR=Emin+1000; end;
PI=ERR;
if MIN_offset>0
   PI=MIN_offset-PI;
   if PI<0, PI=10; end;
end;
if Emin>ERR
   Emin=ERR; 
   fprintf('Se=%f;Sde=%f;dSu=%f;ERR=%f;\n',Se,Sde,dSu,ERR);
end;   
[M, N]=size(Y);
if N==3
   figure(2);plot(T,Y(:,1:3));grid;
else   
   figure(2);plot(T,Y(:,1:2));grid;
end;   
title(['I/O plots, after GA search, Se=' num2str(Se)...
        ',Sde=' num2str(Sde) ',dSu=' num2str(dSu)]);
xlabel('Time(s)') 

⌨️ 快捷键说明

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