24小时热门版块排行榜    

北京石油化工学院2026年研究生招生接收调剂公告
查看: 154  |  回复: 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 ]
回复此楼

» 猜你喜欢

已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
相关版块跳转 我要订阅楼主 someday1985 的主题更新
普通表情 高级回复 (可上传附件)
最具人气热帖推荐 [查看全部] 作者 回/看 最后发表
[考研] 一志愿华东理工大学,080500学硕,317分,求调剂 +13 s1145 2026-03-31 14/700 2026-04-02 18:55 by 哦哦嗯哈
[论文投稿] chinese chemical letters英文版投稿求助 120+4 Yishengeryi 2026-03-30 6/300 2026-04-02 17:19 by Yishengeryi
[考研] 材料专硕322分 +11 哈哈哈吼吼吼哈 2026-04-01 11/550 2026-04-02 10:52 by lnilvy
[考研] 材料科学与工程调剂 +18 深V宿舍吧 2026-03-30 19/950 2026-04-02 10:28 by sanrepian
[基金申请] esi高被引论文是不是能对中标有所加分和帮助呢 +4 redcom 2026-04-01 4/200 2026-04-02 10:16 by wqy8563
[考研] 285求调剂 +11 AZMK 2026-04-01 11/550 2026-04-01 22:40 by peike
[考研] 070300一志愿211,312分求调剂院校 +14 小黄鸭宝 2026-03-30 14/700 2026-04-01 20:19 by 赖春艳
[考研] 【求调剂】085601材料工程专硕 | 总分272 | +10 脚滑的守法公民 2026-03-27 10/500 2026-04-01 17:23 by pies112
[考研] 285求调剂 +5 FZAC123 2026-03-30 5/250 2026-04-01 15:50 by 韩雨涵
[考研] 309分085801求调剂 +7 学员Gtwj7W 2026-03-31 7/350 2026-04-01 02:36 by BruceLiu320
[考研] 一志愿西交大080500材料学硕349 +6 jqx1258 2026-03-31 7/350 2026-03-31 21:08 by yuq
[考研] 合肥区域性重点一本招收调剂 +4 6266jl 2026-03-30 8/400 2026-03-31 18:43 by 6266jl
[考研] 315求调剂 +6 akie... 2026-03-28 7/350 2026-03-31 16:48 by asdfzly
[考研] 343求调剂 +8 爱羁绊 2026-03-28 8/400 2026-03-31 16:12 by 不吃魚的貓
[考研] 生物考研337分求调剂 +4 cgxin 2026-03-30 6/300 2026-03-31 14:18 by 记事本2026
[考研] 本科211安全工程,初试290分,求调剂 +3 2719846834 2026-03-28 3/150 2026-03-31 13:52 by 热情沙漠
[考研] 370求调剂 +3 080700调剂 2026-03-30 3/150 2026-03-31 01:09 by A_Zhe
[考研] 食品工程专硕一志愿中海洋309求调剂 +5 小张zxy张 2026-03-26 10/500 2026-03-31 00:29 by jp9609
[考研] 295求调剂 +5 wei-5 2026-03-26 5/250 2026-03-30 08:34 by 探123
[考研] 343求调剂 +6 爱羁绊 2026-03-29 6/300 2026-03-29 12:00 by 无际的草原
信息提示
请填处理意见