shenzhouxuan 发表于 2009-3-23 17:32

新手请教 遗传算法的求解!!请高手帮忙!!

function=gademo1eval(sol,options)
x=solve(1)
eval=x+10*sin(5*x)+7*cos(4*x);
clc
fplot('x+10*sin(5*x)+7*cos(4*x)',)
initPop=initializega(10,,'gademoleval');
plot(initPop(:,1),initPop(:,2),'b*')
=ga(,'gademoleval',[],initPop,,'maxGenTerm',1,'normGeomSelect',,,,'nonUnifMutation',);
plot(endPop(:,1),endPop(:,2),'bo')
=ga(,'gademoleval',[],initPop,,'maxGenTerm',25,'normGeomSelect',,,,'nonUnifMutation',);
plot (endPop(:,1),endPop(:,2),'y*')
figure(2)
plot(trace(:,1),trace(:,3),'y-')
hold on
plot(trace(:,1),trace(:,2),'r-')
xlabel('Generation');ylabel('Fittness');
legend

问题:
??? Error using ==> eval
Undefined command/function 'gademoleval'.

Error in ==> initializega at 80
eval(estr);

Error in ==> gademo1 at 6
initPop=initializega(10,,'gademoleval');

shenzhouxuan 发表于 2009-3-23 19:02

帮帮忙啊!

Error in ==> initializega at 49
if any(evalFN<48) %Not a .m file





function = initializega(num, bounds, evalFN,evalOps,options)
if nargin<5
options=;
end
if nargin<4
evalOps=[];
end
if any(evalFN<48) %Not a .m file
if options(2)==1 %Float GA
    estr=['x=pop(i,1); pop(i,xZomeLength)=', evalFN ';'];
else %Binary GA
    estr=['x=b2f(pop(i,:),bounds,bits); pop(i,xZomeLength)=', evalFN ';'];
end
else %A .m file
if options(2)==1 %Float GA
    estr=['[ pop(i,:) pop(i,xZomeLength)]=' evalFN '(pop(i,:),);'];
else %Binary GA
    estr=['x=b2f(pop(i,:),bounds,bits);=' evalFN ...
'(x,); pop(i,:)=;'];
    end
end

numVars   = size(bounds,1);   %Number of variables
rng         = (bounds(:,2)-bounds(:,1))'; %The variable ranges'
if options(2)==1 %Float GA
xZomeLength = numVars+1;   %Length of string is numVar + fit
pop         = zeros(num,xZomeLength);%Allocate the new population
pop(:,1:numVars)=(ones(num,1)*rng).*(rand(num,numVars))+...
    (ones(num,1)*bounds(:,1)');
else %Binary GA
bits=calcbits(bounds,options(1));
xZomeLength = sum(bits)+1;   %Length of string is numVar + fit
pop = round(rand(num,sum(bits)+1));
end
for i=1:num
eval(estr);
end

ChaChing 发表于 2009-3-23 22:47

ga没学过, 刚刚help下 (r2006a)
x = ga(fitnessfcn,nvars,A,b,Aeq,beq,LB,UB,nonlcon,options)
好像与楼主调用方式不同!?

yufeng 发表于 2009-3-24 10:23

调用格式出错
页: [1]
查看完整版本: 新手请教 遗传算法的求解!!请高手帮忙!!