| 查看: 153 | 回复: 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 ] |
» 猜你喜欢
体制内长辈说体制内绝大部分一辈子在底层,如同你们一样大部分普通教师忙且收入低
已经有10人回复
过年走亲戚时感受到了所开私家车的鄙视链
已经有9人回复
今年春晚有几个节目很不错,点赞!
已经有10人回复
情人节自我反思:在爱情中有过遗憾吗?
已经有10人回复
基金正文30页指的是报告正文还是整个申请书
已经有5人回复













;
回复此楼