| 查看: 195 | 回复: 0 | |||
| 当前主题已经存档。 | |||
someday1985新虫 (小有名气)
|
[交流]
【求助】请教关于一循环语句的问题
|
||
|
这是我做的遗传算法主程序,我想让popuerr小于某个值,从而退出while循环,是不最后用break语句,该怎么写呢 psize=20;pmutate=0.3;mutatec=0.001; cyc=0;step=ones(1,psize)*0.001; A=rand(1,psize)+1.5; tower=rand(1,psize)+1.0; Sigmag=rand(1,psize)+1.0; tg=rand(1,psize)+2.0; b(:,:,:,1)=A; b(:,:,:,2)=tower; b(:,:,:,3)=Sigmag; b(:,:,:,4)=tg; d=[b(:,:,:,1),b(:,:,:,2),b(:,:,:,3),b(:,:,:,4)]; popu=d'; m=d'; for o=1:1:20 n=m(:,o); i=0; for t=0:0.1:12; i=i+1; A=n(1, ;tower=n(2, ;Sigmag=n(3, ;tg=n(4, ;Z=((t-tg)/Sigmag)-(Sigmag/tower); x=(-1000:0.01:Z)'; y=(1/sqrt(6.28))*exp(-x.*x/2); Vt=trapz(x,y); V2(i)=(A/tower)*exp((Sigmag^2)/(2*tower^2)-((t-tg)/tower)); V2(i)=V2(i)*Vt; end V1=dot(A,tower,tg,Sigmag); popuerr(o)=sumsqr(V2-V1) end popuerr errflow=[]; while cyc<500 cyc=cyc+1; errflow=[errflow,popuerr(1)]; popufit=fitness(popuerr); parent=select(popufit); son1=mate(popu(:,parent)); son2=mutate(son1,pmutate,mutatec); son=[son1,son2]; k=son'; m=k'; for o=1:1:40 n=m(:,o); i=0; for t=0:0.1:12; i=i+1; A=n(1, ;tower=n(2, ;Sigmag=n(3, ;tg=n(4, ;Z=((t-tg)/Sigmag)-(Sigmag/tower); x=(-1000:0.01:Z)'; y=(1/sqrt(6.28))*exp(-x.*x/2); Vt=trapz(x,y); V2(i)=(A/tower)*exp((Sigmag^2)/(2*tower^2)-((t-tg)/tower)); V2(i)=V2(i)*Vt; end V1=dot(A,tower,tg,Sigmag); sonerr(o)=sumsqr(V2-V1); end sonerr sonerr=sum(sonerr); sonfit=fitness(sonerr); popu=[popu,son]; popufit=[popufit,sonfit]; popuerr=[popuerr,sonerr]; offspr=compet(popufit,psize); popu=popu(:,offspr); popuerr=popuerr(offspr); end plot(errflow) disp('The optimal individual is') popu(:,1) [ Last edited by someday1985 on 2010-4-13 at 22:50 ] |
» 猜你喜欢
实名举报:华南理工大学物理与光电学院副院长李志远婚内两次出轨女学生(博士)
已经有8人回复
现代”学阀”该如何界定
已经有7人回复
各位大神,目前国内有哪些比较好用的逆合成软件?
已经有12人回复
我的奶奶
已经有3人回复
申博发邮件
已经有10人回复
国社科系统bug了,是不是要放榜了?
已经有9人回复
上海工程技术大学激光智能制造课题组|2027级博士研究生招生公告
已经有8人回复
上海工程技术大学激光智能制造课题组招收博士研究生
已经有8人回复










;
回复此楼