📄 gga_fis.m
字号:
% Use Chang's GA to find the best PID gain varaibles
% cd d:\ga_chang
% gga_fis.m
% gena_fis.m is defined to evaluate fitness function
%===========================================
global Kp Ki Kd wn zeta Emin main_loop
global tippa MIN_offset MUL_factor
%===========================================
% Define options
Emin=20000; wn=1; zeta=0.1; main_loop=0;
MIN_offset=20000; MUL_factor=1;
tippa=readfis('pidfuzz');
wn=1;zeta=0.1;
% Kp Ki Kd
range=[ 1 1 1
600 10 150];
obj_fcn='gena_fis';
bit_n = 40; % Bit number for each input variable
gen_no =15; % Number of generations
popuSize =22; % Population size
xover_rate = 0.97; % Crossover rate (BETTER)
mutate_rate = 0.04; % Mutation rate (BETTER)
elite=1;
IC=[];
%idmotora
%************************************************************
% call GA written by Chang
tic
[popu, popu_real, fcn_value, upper, average, lower, ...
BEST_popu, popuSize, gen_no, para] = GA_genetic(obj_fcn,...
range, IC, elite, gen_no, popuSize);
tc=toc/60;
fprintf('==> Computation time is (%.2f) minutes.\n',tc);
% Simulate the system and calculate the ERROR.
fprintf('\n <<FINAL RESULTS>> \n'); date
load gena_data; main_loop=1;
figure(3);
xWhitebg;
x = (1:gen_no)';
plot(x, upper, 'o', x, average, 'x', x, lower, '*');
hold on;
plot(x, [upper average lower]);
hold off;
legend('Best', 'Average', 'Poorest');
xlabel('Generations'); ylabel('Fitness');
figure(2);subplot(212);
[t,x,Y]=sim('pidb_fuzzy',[0 20]); y=Y(:,2);in=Y(:,3);
plot(t,[in y]);grid
title('I/O responses, After GA search, gga-fis.m file used')
xlabel(['Time(s),Kp=' num2str(Kp) ',Ki=' num2str(Ki) ',Kd=' num2str(Kd)]);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -