1Matlab在基础物理学中的应用举例(四)(光学:牛顿环的模拟)2011-02-1313:30:18|分类:MatlabSky|标签:matlab光学|字号大中小订阅下面是模拟牛顿环的图案,给出了一个用户交换操作界面的实现程序:closeall;clear;figure('Position',[90164873483]);%设置图形窗口位置L=632.8;R=5;H=0.005;%设置默认参数值:波长L、半径R和厚度Ha1=axes('Position',[0.83,0.3,0.15,0.4]);%设置坐标轴位置,在其上绘制简易的原理图holdon;axis([0,1,0,1]);%设置坐标轴范围plot([0.25,0.25],[0.5,0.8],'r');%画竖直线,入射光线plot([0.5,0.5],[0.5,0.8],'r');%画竖直线,入射光线plot([0.75,0.75],[0.5,0.8],'r');%画竖直线,入射光线fill([0.22,0.25,0.27],[0.5,0.44,0.5],'r');%画出箭头fill([0.47,0.5,0.52],[0.5,0.44,0.5],'r');%画出箭头fill([0.72,0.75,0.77],[0.5,0.44,0.5],'r');%画出箭头z=1.8*exp(i*(linspace(-0.21,0.21,30)-pi/2))+2.1*i+0.5;%生成平凸透镜的轮廓fill(real(z),imag(z),'w');%利用fill函数画平凸透镜的轮廓rectangle('Position',[0.1,0.18,0.8,0.12]);%画玻璃板底面set(gca,'xtick',[],'ytick',[],'box','on');%删去坐标轴刻度a2=axes('Position',[0.4,0.16,0.4,0.7]);%生成第二个坐标轴,在其上画牛顿环[x,y]=meshgrid(linspace(-0.005,0.005,200));%生成坐标矩阵r2=(x.^2+y.^2);%坐标矩阵各点到中心的距离Di=[2*H+2*(R-sqrt(R^2-r2))*1e9]/L;%计算光程差In=abs(cos(Di*pi*2));%得到牛顿环上的光强数值cr=abs(L-560)/200;%红色的分量值cg=1-cr;%绿色的分量值cb=abs(L-600)/240;%蓝色的分量值2Ik(:,:,1)=In*cr;%转化为RGB三基色表示颜色矩阵数值(红色)Ik(:,:,2)=In*cg;%转化为RGB三基色表示颜色矩阵数值(绿色)Ik(:,:,3)=In*cb;%转化为RGB三基色表示颜色矩阵数值(蓝色)Pc=imshow(Ik,[]);%绘制缺省参数下的数值title('thepatternofNewton''srings','fontsize',12);%添加图题%实时显示波长的文本框Lt=uicontrol(gcf,'style','text',...'unit','normalized','position',[0.06,0.86,0.21,0.06],...'BackgroundColor',0.7*[1,1,1],'ForegroundColor',[0.8,0.1,0.9],...'string','wavelength:632.8nm','fontsize',12,'fontname','timesnewroman');s1=uicontrol(gcf,'style','slider',...'unit','normalized','position',[0.06,0.76,0.21,0.04],...'BackgroundColor',0.7*[1,1,1],'ForegroundColor',[0.1,0.1,0.9],...'SliderStep',[0.01,0.01],'value',(632.8-360)/400,...'callback',['L=get(s1,''value'')*400+360;',...'set(Lt,''string'',[''wavelength:'',num2str(L/10),''nm'']);',...'Di=[2*H+2*(R-sqrt(R^2-r2))*1e9]/L;',...'In=abs(cos(Di*pi*2));cr=abs(L-560)/200;cg=1-cr;',...'cb=abs(L-600)/240;Ik(:,:,1)=In*cr;Ik(:,:,2)=In*cg;',...'Ik(:,:,3)=In*cb;set(Pc,''CData'',Ik);']);%利用滑动条改变波长数值uicontrol(gcf,'style','text',...'unit','normalized','position',[0.04,0.81,0.08,0.04],...'BackgroundColor',0.8*[1,1,1],'ForegroundColor',[0.1,0.1,0.9],...'string','360','fontsize',12,'fontname','timesnewroman');%显示最小波长数值uicontrol(gcf,'style','text',...'unit','normalized','position',[0.22,0.81,0.08,0.04],...'BackgroundColor',0.8*[1,1,1],'ForegroundColor',[0.1,0.1,0.9],...'string','760','fontsize',12,'fontname','timesnewroman');%显示最大波长数值3Rt=uicontrol(gcf,'style','text',...'unit','normalized','position',[0.06,0.66,0.23,0.06],...'BackgroundColor',0.7*[1,1,1],'ForegroundColor',[0.8,0.1,0.9],...'string','radii:','fontsize',12,'fontname','timesnewroman');%实时显示半径数值的文本框s2=uicontrol(gcf,'style','slider',...'unit','normalized','position',[0.06,0.56,0.21,0.04],...'BackgroundColor',0.7*[1,1,1],'ForegroundColor',[0.1,0.1,0.9],...'SliderStep',[0.01,0.01],...'callback',['R=get(s2,''value'')*7+5;',...'set(Rt,''string'',[''radii:5m'',num2str(R),''m'']);',...'Di=[2*H+2*(R-sqrt(R^2-r2))*1e9]/L;',...'In=abs(cos(Di*pi*2));cr=abs(L-560)/200;cg=1-cr;',...'cb=abs(L-600)/240;Ik(:,:,1)=In*cr;Ik(:,:,2)=In*cg;',...'Ik(:,:,3)=In*cb;set(Pc,''CData'',Ik);']);%通过滑动条改变半径数值uicontrol(gcf,'style','text',...'unit','normalized','position',[0.04,0.61,0.08,0.04],...'BackgroundColor',0.8*[1,1,1],'ForegroundColor',[0.1,0.1,0.9],...'string','5','fontsize',12,'fontname','timesnewroman');%显示最小半径uicontrol(gcf,'style','text',...'unit','normalized','position',[0.22,0.61,0.08,0.04],...'BackgroundColor',0.8*[1,1,1],'ForegroundColor',[0.1,0.1,0.9],...'string','12','fontsize',12,'fontname','timesnewroman');%显示最大半径%实时显示厚度的文本框Ht=uicontrol(gcf,'style','text',...'unit','normalized','position',[0.06,0.46,0.23,0.06],...'BackgroundColor',0.7*[1,1,1],'ForegroundColor',[0.8,0.1,0.9],...'string','thickness:5nm','fontsize',12,'fontname','timesnewroman');s3=uicontrol(gcf,'style','slider',...'unit','normalized','position',[0.06,0.36,0.21,0.04],...4'BackgroundColor',0.7*[1,1,1],'ForegroundColor',[0.1,0.1,0.9],...'SliderStep',[0.01,0.01],'value',0.05,...'callback',['H=get(s3,''value'')*0.01;',...'set(Ht,''string'',[''thickness:'',num2str(H),''nm'']);',...'Di=[2*H+2*(R-sqrt(R^2-r2))*1e9]/L;',...'In=abs(cos(Di*pi*2));cr=abs(L-560)/200;cg=1-cr;',...'cb=abs(L-600)/240;Ik(:,:,1)=In*cr;Ik(:,:,2)=In*cg;',...'Ik(:,:,3)=In*cb;set(Pc,''CData'',Ik);']);%通过滑动条改变厚度数值uicontrol(gcf,'style','text',...'unit','normalized','position',[0.04,0.41,0.08,0.04],...'BackgroundColor',0.8*[1,1,1],'ForegroundColor',[0.1,0.1,0.9],...'string','0','fontsize',12,'fontname','timesnewroman');%显示最小厚度uicontrol(gcf,'style','text',...'unit','normalized','position',[0.22,0.41,0.08,0.04],...'BackgroundColor',0.8*[1,1,1],'ForegroundColor',[0.1,0.1,0.9],...'string','0.01','fontsize',12,'fontname','timesnewroman');%显示最大厚度运行结果:5