MATLAB爱好者论坛-LabFans.com

MATLAB爱好者论坛-LabFans.com (https://www.labfans.com/bbs/index.php)
-   MATLAB论坛 (https://www.labfans.com/bbs/forumdisplay.php?f=6)
-   -   帮忙看下这个错误怎么解决 (https://www.labfans.com/bbs/showthread.php?t=4809)

houz5559 2008-10-12 11:18

帮忙看下这个错误怎么解决
 
帮忙看下这个一元函数优化代码的错误
f(x)=xsin(10π.x)+2.0 x∈[-1,2]

fplot('variable.*sin(10*pi*variable)+2.0',[-1,2]);
NIND=40;
MAXGEN=25;
PRECI=20;
GGAP=0.9;
trace=zeros(2,MAXGEN);
FieldD=[20;-1;2;1;0;1;1];
Chrom=crtbp(NIND,PRECI);
gen=0;
variable=bs2rv(Chrom,FieldD);
ObjV=variable.*sin(10*pi*variable)+2.0;
while gen<MAXGEN,
FitnV=ranking(-ObjV);
SelCh=select('sus',Chrom,FitnV,GGAP);
SelCh=recombin('xovsp',SelCh,0.7);
SelCh=mut(SelCh);
variable=bs2rv(SelCh,FieldD);
ObjVSel=variable.*sin(10*pi*variable)+2.0;
[Chrom ObjV]=reins(Chrom,SelCh,1,1,ObjV,ObjVSel);
gen=gen+1;
[Y,I]=max(ObjV);hold on;
plot(variable(I),Y,'bo');
trace(1,gen)=max(ObjV);
trace(2,gen)=sum(ObjV)/length(ObjV);
end
variable=bs2rv(Chrom,FieldD);
hold on;grid;
plot(variable',ObjV','b*');
Figure(2);
plot(trace(1,:)');
hold on;
plot(trace(2,:)','-');grid;
legend

??? Undefined function or method 'crtbp' for input arguments of type 'double'.

Error in ==> ttt at 8
Chrom=crtbp(NIND,PRECI);


所有时间均为北京时间。现在的时间是 11:04

Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.