牛顿环演示的matlab程序

牛顿环演示的matlab程序,第1张

L=632.8R=5H=5

a2=axes('Position',[0.4,0.16,0.4,0.7]) %图片滚则在figure中的位置 前两个代表x方向的坐标,后两个是y方向的凯备敏坐标

[x,y]=meshgrid(linspace(-0.005,0.005,200))%%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%rgb 色彩取值

cg=1-cr

cb=abs(L-600)/240

Ik(:,:,1)=In*cr %颜色的设置

Ik(:,:,2)=In*cg

Ik(:,:,3)=In*cb

Pc=imshow(Ik,[]) %显示图片

% 牛顿环演示的MATLAB程序

close allclearclc

figure('Position',[90 164 873 483])

L=632.8R=5H=5

a1=axes('Position',[0.83,0.3,0.15,0.4])

hold onaxis([0,1,0,1])

plot([0.25,0.25],[0.5,0.8],'k')

plot([0.5,0.5],[0.5,0.8],'k')

plot([0.75,0.75],[0.5,0.8],'k')

fill([0.22,0.25,0.27],[0.5,0.44,0.5],'k')

fill([0.47,0.5,0.52],[0.5,0.44,0.5],'k')

fill([0.72,0.75,0.77],[0.5,0.44,0.5],'k')

z=1.8*exp(i*(linspace(-0.21,0.21,30)-pi/2))+2.1*i+0.5

fill(real(z),imag(z),'w'搭肆)

rectangle('Position',[0.1,0.18,0.8,0.12])

set(gca,'xtick',[],'ytick',[],'box','on')

% \copyright: zjliu

% Author's email: zjliu2001@163.com

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

Ik(:,:,1)=In*cr

Ik(:,:,2)=In*cg

Ik(:,:,3)=In*cb

Pc=imshow(Ik,[])

title('the pattern of Newton''s rings','fontsize',18)

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','激枝厅波长: 632.8nm','fontsize',16,'fontname','times new roman')

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'',[''波长: '',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)/200cg=1-cr',...

'cb=abs(L-600)/240Ik(:,:,1)=In*crIk(:,:,2)=In*cg',...

'Ik(:,:,3)=In*cbset(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',16,'fontname','times new roman')

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',16,'fontname','times new roman')

Rt=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','曲率半径:','fontsize',16,'fontname','times new roman')

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'',[''曲率半径: 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)/200cg=1-cr',...

'cb=abs(L-600)/240Ik(:,:,1)=In*crIk(:,:,2)=In*cg',...

'Ik(:,:,3)=In*cbset(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',16,'fontname','times new roman')

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',16,'fontname','times new roman')

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','气缝厚度: 5nm','fontsize',16,'fontname','times new roman')

s3=uicontrol(gcf,'style','slider',...

'unit','normalized','position',[0.06,0.36,0.21,0.04],...

'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'')*100',...

'set(Ht,''string'',[''气缝厚度: '',num2str(H),''nm''])',...

'Di=[2*H+2*(R-sqrt(R^2-r2))*1e9]/L',...

'In=abs(cos(Di*pi*2))cr=abs(L-560)/200cg=1-cr',...

'cb=abs(L-600)/240Ik(:,:,1)=In*crIk(:,:,2)=In*cg',...

'Ik(:,:,3)=In*cbset(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',16,'fontname','times new roman')

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','100','fontsize',16,'fontname','times new roman')

%%%% Note

uicontrol(gcf,'style','text',...

'unit','normalized','position',[0.05,0.08,0.68,0.07],...

'BackgroundColor',0.8*[1,1,1],'ForegroundColor',[0.8,0.2,0.2],...

'string','颜色和波长的关系可能不准确,我只是根据大致的关系写的',...

'fontsize',16,'fontname','times new roman')

uicontrol(gcf,'style','text',...

'unit','normalized','position',[0.05,0.02,0.6,0.07],...

'BackgroundColor',0.8*[1,1,1],'ForegroundColor',[0.9,0.2,0.5],...

'string','\Copyright zjliu, email: zjliu2001@163.com',...

'fontsize',16,'fontname','times new roman')

%牛顿环

clear %清除变量

rm=5 %最大半径(相对坐标)

r=-rm:0.01:rm %横坐标或纵坐标向量

[X,Y]=meshgrid(r) %横坐标和纵坐标矩阵

R=sqrt(X.^2+Y.^2) %求各点到圆心的距离

I=cos(pi*(R.^2+1/2)).^2 %反射光的相对光强

I(R>rm)=0 %最大灶斗局半径外的光强改为0(将方形图改为圆形图,四角为黑色)

c=linspace(0,1,64)' %颜色范围

figure %建立图形窗口

h=image(I*64) %画图像

ColorMap=([c,c*0,c*0]) %形成红色色图

%ColorMap([c,c,c*0]) %形成黄色色图

%ColorMap([c,c,c]) %形成白色色图

axis off equal %隐轴

title('牛顿环(反射光)','FontSize',16) %标题

pause %暂停

d=0 %初始距离销档

while 1 %无限循环

d=d+0.02 %增加距离

I=cos(pi*(R.^2+1/2+2*d)).^2 %反射光的相对光强

I(R>rm)=0 %最大半径外的光强改为0

set(h,'CData',64*I) %设置光强

drawnow %更新屏幕

if get(gcf,'隐让CurrentCharacter')==char(27) break,end%按ESC键退出

end %结束循环


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/12447803.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-25
下一篇 2023-05-25

发表评论

登录后才能评论

评论列表(0条)

保存