📄 ga_ex21a.m
字号:
% GA_ex21A.m file
% Fin min of a function of 2 varaibles
% PenChen Chou, 7-1-2001
clear all
ans=1;
who
fprintf('>>>Start this program now. Please wait!\n');
pause(1)
global MIN_offset MUL_factor LOCUS x_data y_data
MIN_offset=250; LOCUS=1; x_data=[]; y_data=[];
MUL_factor=1;
%**********************************************************/
% User can modify the following in blocks
%**********************************************************/
obj_fcn = 'GA_f21m'; % Objective function
range = [0 0
10 10]; % Range of the input variables
IC=[]; elite=1;
gen_no=300;
popuSize=30;
bit_n=30;
xover_rate=0.8;
mutate_rate=0.05;
x=0:0.1:10; y=x; [X,Y]=meshgrid(x,y);
Z=X.*sin(4*X)+1.1*Y.*sin(2*Y);
figure(2);contour(X,Y,Z)
%************************************************************
% call GA written by Chang
tic
%GA_genetic(obj_fcn, range, IC, elite,...
% gen_no, popuSize, bit_n, xover_rate, mutate_rate);
[popu, popu_real, fcn_value, upper, average, lower, ...
popuSize, gen_no] = 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\n',t);
% Plot locus of optimization process
LAST=length(x_data);
figure(2); hold on
plot(x_data(1),y_data(1),'x');
plot(x_data,y_data);
plot(x_data(LAST),y_data(LAST),'o');
%plot(0,0,'*'); % The best position
hold off
title('*=BEST, x=Starting point, o=Ending point')
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -