您好,欢迎访问三七文档
当前位置:首页 > 临时分类 > 抗体模型乘法公式实验案例4
%polya_kangti.mfunctionpolya_kangtialpha=0:pi/200:2*pi;r=0.5;h=20;b=20;whileh0&&b0%当病毒和抗体都存在时,战斗继续clf;axis([025025])plot([12.5,12.5],[0,25],'LineWidth',5,'color','m');holdonfori=1:h%确定红球的坐标oxh(i)=(floor((i-1)/10)+1)*4;oyh(i)=rem(i-1,10)*2+4;endfori=1:b%确定蓝球的坐标oxb(i)=(floor((i-1)/10)+1)*4+13;oyb(i)=rem(i-1,10)*2+4;endanswer=ceil(rand*(b+h));%随机产生一个1到b+h的整数text(9.5,13,'人','FontSize',18,'color','r');text(9.5,11,'体','FontSize',18,'color','r');text(13.5,13,'病','FontSize',18,'color','b');text(13.5,11,'毒','FontSize',18,'color','b');ifanswerh%如果抽中蓝球,随机找一个蓝球消灭两个红球k1=ceil(rand*h);%随机产生一个1到h的整数k=randperm(b);%将1到b的整数随机排序k2=k(1);k3=k(2);fori=1:h%画出h个红球x0=oxh(i);y0=oyh(i);x=r*cos(alpha)+x0;y=r*sin(alpha)+y0;plot(x,y);axissquare;axis([025025])fill(x,y,'r');endfori=1:b%画出b个蓝球x0=oxb(i);y0=oyb(i);x=r*cos(alpha)+x0;y=r*sin(alpha)+y0;plot(x,y);axissquare;axis([025025])fill(x,y,'b');endt=0:0.1:sqrt((oxb(k2)-oxh(k1))^2+(oyb(k2)-oyh(k1))^2);x=oxh(k1)+t*(oxb(k2)-oxh(k1))/sqrt((oxb(k2)-oxh(k1))^2+(oyb(k2)-oyh(k1))^2);y=oyh(k1)+t*(oyb(k2)-oyh(k1))/sqrt((oxb(k2)-oxh(k1))^2+(oyb(k2)-oyh(k1))^2);comet(x,y);axis([025025])%画彗星图模拟蓝球对红球的攻击t=0:0.1:sqrt((oxb(k3)-oxh(k1))^2+(oyb(k3)-oyh(k1))^2);x=oxh(k1)+t*(oxb(k3)-oxh(k1))/sqrt((oxb(k3)-oxh(k1))^2+(oyb(k3)-oyh(k1))^2);y=oyh(k1)+t*(oyb(k3)-oyh(k1))/sqrt((oxb(k3)-oxh(k1))^2+(oyb(k3)-oyh(k1))^2);comet(x,y);axis([025025])%画彗星图模拟蓝球对红球的攻击b=b-2;%蓝球个数减少两个else%如果抽中红球,随机找一个红球消灭两个蓝球k1=ceil(rand*b);%随机产生一个1到b的整数k=randperm(h);%将1到h的整数随机排序k2=k(1);k3=k(2);fori=1:h%画出h个红球x0=oxh(i);y0=oyh(i);x=r*cos(alpha)+x0;y=r*sin(alpha)+y0;plot(x,y);axissquare;axis([025025])fill(x,y,'r');endfori=1:b%画出b个蓝球x0=oxb(i);y0=oyb(i);x=r*cos(alpha)+x0;y=r*sin(alpha)+y0;plot(x,y);axissquare;axis([025025])fill(x,y,'b');endt=0:0.1:sqrt((oxh(k2)-oxb(k1))^2+(oyh(k2)-oyb(k1))^2);x=oxb(k1)+t*(oxh(k2)-oxb(k1))/sqrt((oxh(k2)-oxb(k1))^2+(oyh(k2)-oyb(k1))^2);y=oyb(k1)+t*(oyh(k2)-oyb(k1))/sqrt((oxh(k2)-oxb(k1))^2+(oyh(k2)-oyb(k1))^2);comet(x,y);axis([025025])%画彗星图模拟红球对蓝球的攻击t=0:0.1:sqrt((oxh(k3)-oxb(k1))^2+(oyh(k3)-oyb(k1))^2);x=oxb(k1)+t*(oxh(k3)-oxb(k1))/sqrt((oxh(k3)-oxb(k1))^2+(oyh(k3)-oyb(k1))^2);y=oyb(k1)+t*(oyh(k3)-oyb(k1))/sqrt((oxh(k3)-oxb(k1))^2+(oyh(k3)-oyb(k1))^2);comet(x,y);axis([025025])%画彗星图模拟红球对蓝球的攻击h=h-2;endifb==0text(13.5,20,'病毒已被消灭!','FontSize',18,'color','r')break;elseifh==0text(1.5,20,'人危矣!','FontSize',18,'color','b')break;endend
本文标题:抗体模型乘法公式实验案例4
链接地址:https://www.777doc.com/doc-2370490 .html