MATLAB运行明明已经定义了参数 为啥总报错说未定义function [xv,fv]=GMGA(fitness,a,b,NP,NG,Pc,Pm,alpha,Pbm,eps)%大变异遗传算法L = ceil(log2((b-a)/eps+1));x = zeros(NP,L);for i=1:NP x(i,:) = Initial(L); fx(i) = fitness(Dec(a,b,x
来源:学生作业帮助网 编辑:六六作业网 时间:2024/12/26 05:14:48
MATLAB运行明明已经定义了参数 为啥总报错说未定义function [xv,fv]=GMGA(fitness,a,b,NP,NG,Pc,Pm,alpha,Pbm,eps)%大变异遗传算法L = ceil(log2((b-a)/eps+1));x = zeros(NP,L);for i=1:NP x(i,:) = Initial(L); fx(i) = fitness(Dec(a,b,x
MATLAB运行明明已经定义了参数 为啥总报错说未定义
function [xv,fv]=GMGA(fitness,a,b,NP,NG,Pc,Pm,alpha,Pbm,eps)
%大变异遗传算法
L = ceil(log2((b-a)/eps+1));
x = zeros(NP,L);
for i=1:NP
x(i,:) = Initial(L);
fx(i) = fitness(Dec(a,b,x(i,:),L));
end
for k=1:NG
sumfx = sum(fx);
favg = sumfx/NP;
[fmax,xmax] = max(fx);
if k NP=50;
>> NG=500;
>> Pc=0.9;
>> Pm=0.03;
>> alpha=0.6;
>> Pbm=0.2;
>> eps=0.01;
在输入GMGA运行上面那个程序
报错?Input argument "b" is undefined.
Error in ==> GMGA at 3
L = ceil(log2((b-a)/eps+1));
可是我b已经定义了啊!
MATLAB运行明明已经定义了参数 为啥总报错说未定义function [xv,fv]=GMGA(fitness,a,b,NP,NG,Pc,Pm,alpha,Pbm,eps)%大变异遗传算法L = ceil(log2((b-a)/eps+1));x = zeros(NP,L);for i=1:NP x(i,:) = Initial(L); fx(i) = fitness(Dec(a,b,x
貌似应该提示是变量 a没有定义猜对吧.
既然是个函数,不能直接运行了; 注意,在命令行模式运行的时候要这样:
[xv,fv]=GMGA(fitness,a,b,NP,NG,Pc,Pm,alpha,Pbm,eps)