美赛A题基于某NS模型的超车模型Matlab代码新鲜出炉.docx
- 文档编号:20267335
- 上传时间:2023-04-25
- 格式:DOCX
- 页数:21
- 大小:18.01KB
美赛A题基于某NS模型的超车模型Matlab代码新鲜出炉.docx
《美赛A题基于某NS模型的超车模型Matlab代码新鲜出炉.docx》由会员分享,可在线阅读,更多相关《美赛A题基于某NS模型的超车模型Matlab代码新鲜出炉.docx(21页珍藏版)》请在冰豆网上搜索。
美赛A题基于某NS模型的超车模型Matlab代码新鲜出炉
plotbutton=uicontrol('style','pushbutton',...
'string','Run',...
'fontsize',12,...
'position',[100,400,50,20],...
'callback','run=1;');
%definethestopbutton
erasebutton=uicontrol('style','pushbutton',...
'string','Stop',...
'fontsize',12,...
'position',[200,400,50,20],...
'callback','freeze=1;');
%definetheQuitbutton
quitbutton=uicontrol('style','pushbutton',...
'string','Quit',...
'fontsize',12,...
'position',[300,400,50,20],...
'callback','stop=1;close;');
number=uicontrol('style','text',...
'string','1',...
'fontsize',12,...
'position',[20,400,50,20]);
%==============================
%CAsetup
n=128;
%initializethearrays
z=zeros(n,n);
cells=z;
sum=z;
%setafewcellstoone
cells(n/2,.25*n:
.75*n)=1;
cells(.25*n:
.75*n,n/2)=1;
%cells(.5*n-1,.5*n-1)=1;
%cells(.5*n-2,.5*n-2)=1;
%cells(.5*n-3,.5*n-3)=1;
cells=(rand(n,n))<.5;
%howlongforeachcasetostabilityorsimpleoscillators
%buildanimageanddisplayit
imh=image(cat(3,cells,z,z));
set(imh,'erasemode','none')
axisequal
axistight
%indexdefinitionforcellupdate
x=2:
n-1;
y=2:
n-1;
%Maineventloop
stop=0;%waitforaquitbuttonpush
run=0;%waitforadraw
freeze=0;%waitforafreeze
while(stop==0)
if(run==1)
%nearestneighborsum
sum(x,y)=cells(x,y-1)+cells(x,y+1)+...
cells(x-1,y)+cells(x+1,y)+...
cells(x-1,y-1)+cells(x-1,y+1)+...
cells(3:
n,y-1)+cells(x+1,y+1);
%TheCArule
cells=(sum==3)|(sum==2&cells);
%drawthenewimage
set(imh,'cdata',cat(3,cells,z,z))
%updatethestepnumberdiaplay
stepnumber=1+str2num(get(number,'string'));
set(number,'string',num2str(stepnumber))
end
if(freeze==1)
run=0;
freeze=0;
end
drawnow%needthisintheloopforcontrolstowork
end
2、SurfaceTension
%Conway'slifewithGUI
clf;clearall
%=============================================
%buildtheGUI
%definetheplotbutton
plotbutton=uicontrol('style','pushbutton',...
'string','Run',...
'fontsize',12,...
'position',[100,400,50,20],...
'callback','run=1;');
%definethestopbutton
erasebutton=uicontrol('style','pushbutton',...
'string','Stop',...
'fontsize',12,...
'position',[200,400,50,20],...
'callback','freeze=1;');
%definetheQuitbutton
quitbutton=uicontrol('style','pushbutton',...
'string','Quit',...
'fontsize',12,...
'position',[300,400,50,20],...
'callback','stop=1;close;');
number=uicontrol('style','text',...
'string','1',...
'fontsize',12,...
'position',[20,400,50,20]);
%=============================================
%CAsetup
n=128;
%initializethearrays
z=zeros(n,n);
cells=z;
sum=z;
%setafewcellstoone
cells(n/2,.25*n:
.75*n)=1;
cells(.25*n:
.75*n,n/2)=1;
%cells(.5*n-1,.5*n-1)=1;
%cells(.5*n-2,.5*n-2)=1;
%cells(.5*n-3,.5*n-3)=1;
cells=(rand(n,n))<.5;
%howlongforeachcasetostabilityorsimpleoscillators
%buildanimageanddisplayit
imh=image(cat(3,cells,z,z));
set(imh,'erasemode','none')
axisequal
axistight
%indexdefinitionforcellupdate
x=2:
n-1;
y=2:
n-1;
%Maineventloop
stop=0;%waitforaquitbuttonpush
run=0;%waitforadraw
freeze=0;%waitforafreeze
while(stop==0)
if(run==1)
%nearestneighborsum
sum(x,y)=cells(x,y-1)+cells(x,y+1)+...
cells(x-1,y)+cells(x+1,y)+...
cells(x-1,y-1)+cells(x-1,y+1)+...
cells(3:
n,y-1)+cells(x+1,y+1)+...
cells(x,y);
%TheCArule
cells=~((sum<4)|(sum==5));
%drawthenewimage
set(imh,'cdata',cat(3,cells,z,z))
%updatethestepnumberdiaplay
stepnumber=1+str2num(get(number,'string'));
set(number,'string',num2str(stepnumber))
end
if(freeze==1)
run=0;
freeze=0;
end
drawnow%needthisintheloopforcontrolstowork
end
3、PercolationCluster
%PercolationCluster
clf
clearall
threshold=.63;
%
ax=axes('units','pixels','position',[11500400],'color','k');
text('units','pixels','position',[50,255,0],...
'string','BioNB','color','w','fontname','helvetica','fontsize',100)
text('units','pixels','position',[120,120,0],...
'string','441','color','w','fontname','helvetica','fontsize',100)
initial=getframe(gca);
[a,b,c]=size(initial.cdata);
z=zeros(a,b);
cells=double(initial.cdata(:
:
1)==255);
visit=z;
sum=z;
imh=image(cat(3,z,cells,z));
set(imh,'erasemode','none')
%return
fori=1:
100
sum(2:
a-1,2:
b-1)=cells(2:
a-1,1:
b-2)+cells(2:
a-1,3:
b)+...
cells(1:
a-2,2:
b-1)+cells(3:
a,2:
b-1)+...
cells(1:
a-2,1:
b-2)+cells(1:
a-2,3:
b)+...
cells(3:
a,1:
b-2)+cells(3:
a,3:
b);
pick=rand(a,b);
%edgesonly
%cells=(cells&(sum<8))|((sum>=1)&(pick>=threshold)&(visit==0));
cells=cells|((sum>=1)&(pick>=threshold)&(visit==0));
visit=(sum>=1);%&(pick set(imh,'cdata',cat(3,z,cells,z)) drawnow end return figure (2) image(cat(3,z,cells,z)) 4、Excitablemedia(BZreactionorheart) %CAdriver %excitablemedia clf;clearall n=128; z=zeros(n,n); cells=z; cells=(rand(n,n))<.1; %cells(n/2,n*.25: n*.75)=1; %cells(n*.25: n*.75,n/2)=1; sum=z; imh=image(cat(3,cells,z,z)); set(imh,'erasemode','none') axisequal axistight x=[2: n-1];y=[2: n-1]; t=6;%centervalue=6;7makesfastpattern;5analiatingwaves t1=3;%centervalue=3 fori=1: 1200 sum(x,y)=((cells(x,y-1)>0)&(cells(x,y-1) ((cells(x-1,y)>0)&(cells(x-1,y) ((cells(x-1,y-1)>0)&(cells(x-1,y-1) ((cells(x+1,y-1)>0)&(cells(x+1,y-1) cells=((cells==0)&(sum>=t1))+... 2*(cells==1)+... 3*(cells==2)+... 4*(cells==3)+... 5*(cells==4)+... 6*(cells==5)+... 7*(cells==6)+... 8*(cells==7)+... 9*(cells==8)+... 0*(cells==9); set(imh,'cdata',cat(3,z,cells/10,z)) drawnow end 5、ForestFire %CAdriver % %forestfire clf clearall n=100; Plightning=.000005; Pgrowth=.01;%.01 z=zeros(n,n); o=ones(n,n); veg=z; sum=z; imh=image(cat(3,z,veg*.02,z)); set(imh,'erasemode','none') axisequal axistight %burning->empty %green->burningifoneneigborburningorwithprob=f(lightning) %empty->greenwithprob=p(growth) %veg={empty=0burning=1green=2} fori=1: 3000 %nearbyfires? sum=(veg(1: n,[n1: n-1])==1)+(veg(1: n,[2: n1])==1)+... (veg([n1: n-1],1: n)==1)+(veg([2: n1],1: n)==1); veg=... 2*(veg==2)-((veg==2)&(sum>0|(rand(n,n) 2*((veg==0)&rand(n,n) set(imh,'cdata',cat(3,(veg==1),(veg==2),z)) drawnow end 6、Gasdynamics %CAdriver %HPP-gas clearall clf nx=52;%mustbedivisibleby4 ny=100; z=zeros(nx,ny); o=ones(nx,ny); sand=z; sandNew=z; gnd=z; diag1=z; diag2=z; and12=z; or12=z; sums=z; orsum=z; gnd(1: nx,ny-3)=1;%rightgroundline gnd(1: nx,3)=1;%leftgroundline gnd(nx/4: nx/2-2,ny/2)=1;%theholeline gnd(nx/2+2: nx,ny/2)=1;%theholeline gnd(nx/4,1: ny)=1;%topline gnd(3*nx/4,1: ny)=1;%bottomline %filltheleftside r=rand(nx,ny); sand(nx/4+1: 3*nx/4-1,4: ny/2-1)=r(nx/4+1: 3*nx/4-1,4: ny/2-1)<0.3; %sand(nx/4+1: 3*nx/4-1,ny*.75: ny-4)=r(nx/4+1: 3*nx/4-1,ny*.75: ny-4)<0.75; %sand(nx/2,ny/2)=1; %sand(nx/2+1,ny/2+1)=1; imh=image(cat(3,z,sand,gnd)); set(imh,'erasemode','none') axisequal axistight fori=1: 1000 p=mod(i,2);%margolisneighborhood %upperleftcellupdate xind=[1+p: 2: nx-2+p]; yind=[1+p: 2: ny-2+p]; %Seeifexactlyonediagonalisones %only(atmost)oneofthefollowingcanbetrue! diag1(xind,yind)=(sand(xind,yind)==1)&(sand(xind+1,yind+1)==1)&... (sand(xind+1,yind)==0)&(sand(xind,yind+1)==0); diag2(xind,yind)=(sand(xind+1,yind)==1)&(sand(xind,yind+1)==1)&... (sand(xind,yind)==0)&(sand(xind+1,yind+1)==0); %Thediagonalsbothnotoccupiedbytwoparticles and12(xind,yind)=(diag1(xind,yind)==0)&(diag2(xind,yind)==0); %Onediagonalisoccupiedbytwoparticles or12(xind,yind)=diag1(xind,yind)|diag2(xind,yind); %foreverygasparticleseeifitneartheboundary sums(xind,yind)=gnd(xind,yind)|gnd(xind+1,yind)|... gnd(xind,yind+1)|gnd(xind+1,yind+1); %celllayout: %x,yx+1,y %x,y+1x+1,y+1 %If(nowalls)and(diagonalsarebothnotoccupied) %thenthereisnocollision,somoveoppositecelltocurrentcell %If(nowalls)and(onlyonediagonalisoccupied) %thenthereisacollisionsomoveccwcelltothecurrentcell %If(awall) %thendon'tchangethecell(causesareflection) sandNew(xind,yind)=... (and12(xind,yind)&~sums(xind,yind)&sand(xind+1,yind+1))+... (or12(xind,yind)&~sums(xind,yind)&sand(xind,yind+1))+... (sums(xind,yind)&sand(xind,yind)); sandNew(xind+1,yind)=... (and12(xind,yind)&~sums(xind,yind)&sand(xind,yind+1))+... (or12(xind,yind)&~sums(xind,yind)&sand(xind,yind))+... (sums(xind,yind)&sand(xind+1,yind)); sandNew(xind,yind+1)=... (and12(xind,yind)&~sums(xind,yind)&sand(xind+1,yind))+... (or12(xind,yind)&~sums(xind,yind)&sand(xind+1,yind+1))+... (sums(xind,yind)&sand(xind,yind+1)); sandNew(xind+1,yind+1)=... (and12(xind,yind)&~sums(xind,yin
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 基于 NS 模型 超车 Matlab 代码 新鲜 出炉
![提示](https://static.bdocx.com/images/bang_tan.gif)