ga_ex614c.m

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

M
77
字号
% GA_ex614c.m file
% Find weights and bias of a NN control system by using GA

% PenChen Chou, 7-29-2001

%**********************************************************/
%       User can modify the following in blocks
%**********************************************************/
clear all
ans=1;
who
fprintf('>>>Start this program [GA_ex614c.m] now. Please wait!\n');
pause(1)

global MIN_offset MUL_factor LOCUS x_data y_data 
global Emin MDL r_deg Init_P Init_V FT Mode
global V11 V12 V21 V22 W11 W12 b11 b21 c11 K a1 a2 Se Sde Su

%MDL='negf_nn'; eval(MDL); FT=5; Mode=0;
MDL='negfc_nn'; %eval(MDL); 
FT=7.5; Mode=1;
FT=18;
MIN_offset=8e3; LOCUS=0; x_data=[]; y_data=[];
MUL_factor=1;
Emin=MIN_offset;
obj_fcn = 'GA_f614c';	% Objective function
UB=5.5*ones(1,9); LB=-UB;
LB=[LB 0.001 0.001 0.1]; % Append Se Sde Su
UB=[UB  160   160    1];
range = [LB;UB];
IC=[];elite=1;
gen_no=105;  popuSize=60;
bit_n=35; xover_rate=0.7; mutate_rate=0.1;

% This is the NN net we can use in this program. Don't change it.
net = newff([0 1;0 1],[2 1],{'tansig' 'purelin'});
%************************************************************
% 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, bit_n, xover_rate,...
    mutate_rate);
t=toc/60;

fprintf('==>  Computation time is (%.2f) minutes.\n',t);            
            
% Show the result using parameters found by GA
K=10; a1=2; a2=3;
V11=para(1);
V12=para(2);
V21=para(3);
V22=para(4);
b11=para(5);
b21=para(6);
W11=para(7);
W12=para(8);
c11=para(9);
Se =para(10);
Sde=para(11);
Su =para(12);
if Mode==0
    Ftime=5;
else
    Ftime=18;
end;    
[t, X, Y]=sim(MDL,[0:0.05:Ftime]);
in=Y(:,2); x1=Y(:,3); x2=Y(:,4);
figure(2);subplot(211);plot(t,[in x1]);
title('Antenna angle command and output responses(deg.)');
figure(2);subplot(212);plot(t,[x2]);
title('Antenna angle velocity output response(deg./s)');
xlabel('Time(s)');

⌨️ 快捷键说明

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