Y-BH

double_slit_experiment_MATLAB

Apr 28th, 2020
676
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 1.09 KB | None | 0 0
  1. %电子通过双缝的干涉图样的演示
  2. clc;clear
  3. close all
  4. path=char('.\pic_seqs\');
  5. if exist(path,'dir')==7
  6.     rmdir(path,'s')% 删除旧文件
  7. end
  8. mkdir(path)
  9. dpi=1.25;% imwrite使用系统缩放125%;
  10. scr=[1920 1080];% 屏幕分辨率
  11. res=[1200 800];% 图像分辨率
  12. k=0.5;xm=5*pi;n=1e3;% n=1e3为总电子数,打在光屏显示约一半
  13. set(gcf,'Color','#000000');% 更改背景颜色
  14. fig=gcf;
  15. fig.Position = [(scr-res)/2,res]/dpi;% 居中显示
  16. title('电子数=0',...
  17.     'FontName','黑体','FontSize',20,'Color','w');
  18. axis([-xm,xm,0,1])
  19. axis off
  20. m0=getframe(gcf);
  21. imwrite(m0.cdata,[path,'0.png']);
  22. ii=0;
  23. for nn=1:n
  24.     x=2*xm*(rand(1)-0.5);y=rand(1);
  25.     i=cos(k*x)^2;
  26.     r=rand(1);
  27.     if r<=i %随机数在概率之内时为逻辑真
  28.         ii=ii+1;
  29.         plot(x,y,'.','Color','w','markersize',5)
  30.         title(['电子数=' num2str(ii)],...
  31.             'FontName','黑体','FontSize',20,'Color','w');
  32.         axis([-xm,xm,0,1])
  33.         axis off
  34.         hold on
  35.         m(ii)=getframe(gcf);
  36.         imwrite(m(ii).cdata,[path,num2str(ii),'.png']);
  37.     end
  38. end
Add Comment
Please, Sign In to add comment