yitianjian 发表于 2008-7-15 20:05

请高手指点一下这段遗传算法程序

这是书上的一个例子,但是我运行总是报错,请高手指点一下,谢啦!


用遗传算法计算下列函数的最大值:
f(x)=x+10*sin(5x)+7*cos(4x)   (0<x<9)


function=initializega(num,bounds,eevalFN)

function=ga(bounds,evalFN,evalOps,startpop,opts,termFN,termOps,selectFN,selectOps,xOverFNs,xOverOps,mutFNs,mutOps)

function=gademo1eeval1(sol,options) //目标函数
x=sol(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,,'gademo1eeval1');
plot(initpop(:,1),initpop(:,2),'b*')
=ga(,'gademo1eeval1',[],initpop,,'maxgenterm',1,'normgeomselect',,['arithxover'],,'nonunifmutation',)
plot(endpop(:,1),endpop(:,2),'bo')
=ga(,'gademo1eeval1',[],initpop,,'maxgenterm',25,'normgeomselect',,['arithxover'],,'nonunifmutation',)
plot(endpop(:,1),endpop(:,2),'y*')
figure(2)
plot(trace(:,1),trace(:,3),'y-')
hold on
plot(trace(:,1),trace(:,2),'r-')
xlabel('genetation');
ylabel('fittness');
legend;
页: [1]
查看完整版本: 请高手指点一下这段遗传算法程序