Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- %电子通过双缝的干涉图样的演示
- clc;clear
- close all
- path=char('.\pic_seqs\');
- if exist(path,'dir')==7
- rmdir(path,'s')% 删除旧文件
- end
- mkdir(path)
- dpi=1.25;% imwrite使用系统缩放125%;
- scr=[1920 1080];% 屏幕分辨率
- res=[1200 800];% 图像分辨率
- k=0.5;xm=5*pi;n=1e3;% n=1e3为总电子数,打在光屏显示约一半
- set(gcf,'Color','#000000');% 更改背景颜色
- fig=gcf;
- fig.Position = [(scr-res)/2,res]/dpi;% 居中显示
- title('电子数=0',...
- 'FontName','黑体','FontSize',20,'Color','w');
- axis([-xm,xm,0,1])
- axis off
- m0=getframe(gcf);
- imwrite(m0.cdata,[path,'0.png']);
- ii=0;
- for nn=1:n
- x=2*xm*(rand(1)-0.5);y=rand(1);
- i=cos(k*x)^2;
- r=rand(1);
- if r<=i %随机数在概率之内时为逻辑真
- ii=ii+1;
- plot(x,y,'.','Color','w','markersize',5)
- title(['电子数=' num2str(ii)],...
- 'FontName','黑体','FontSize',20,'Color','w');
- axis([-xm,xm,0,1])
- axis off
- hold on
- m(ii)=getframe(gcf);
- imwrite(m(ii).cdata,[path,num2str(ii),'.png']);
- end
- end
Add Comment
Please, Sign In to add comment