资 源 简 介
clc;
clear;
%%%%%%%%%%%%%%%%%%%%初始化%%%%%%%%%%%%%%%%%%%%%%%
M=50; %种群大小
Pc=0.6; %交叉概率
Pm=0.001; %变异概率
l_limit=-10; %求解区间下限
h_limit=10; %求解区间上限
delta=1/10000; %所需精度
generations=500 ; %繁衍代数
a=(h_limit-l_limit)/delta+1; %临时变量
f=@(x)(sin(x)./x); %目标函数
for icnt=0:inf
if a<2^icnt
break;
end
end
if mod(icnt,2)==0
l=icnt; %染色体长度
else
l=icnt+1;
end
delta=(h_limit-l_limit)/(2^l-1); %实际精度
x=l_limit:0.01:h_limit;
plot(x,f(x),"LineWidth",3),grid %函数图象
%%%%%%%%%%%%%%%%%%%%初始化%%%%%%%%%%%%%%%%%%%%%%%%
[x,b,c,d]=fminunc(f,-10)
%%%%%%%%%%%%%%%%%%%%构造种群%%%%%%%%%%%%%%%%%%%%%%
group=round(unifrnd(0,2^l-1,1,M));
%%%%%%%%%%%%%%%%%%%%构造种群%%%%%%%%%%%%%%%%%%%%%%
for lcnt=1:generations
%%%%%%%%%%%%%%%%