一、获取代码方式
获取代码方式1:
完整代码已上传我的资源:【光学】基于matlab GUI干涉衍射仿真【含Matlab源码 1723期】
二、部分源代码
%双缝干涉可改D或f和间距
%等倾干涉可改厚度和角度
%等厚干涉可改波长
%衍射的焦距是公共的
%距孔衍射是以长为基的正方孔
% HUAS 201611030117
function varargout = GS_YS(varargin)
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @GS_YS_OpeningFcn, ...
'gui_OutputFcn', @GS_YS_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before GS_YS is made visible.
function GS_YS_OpeningFcn(hObject, eventdata, handles, varargin)
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% --- Outputs from this function are returned to the command line.
function varargout = GS_YS_OutputFcn(hObject, eventdata, handles)
varargout{1} = handles.output;
% --- Executes on button press in pushbutton1_ShF.
function pushbutton1_ShF_Callback(hObject, eventdata, handles)
lambda=632e-9;
% d=0.002; %双缝间距d
d=str2num(get(handles.ShF_jianju,'string'));
D=str2num(get(handles.D_or_f,'string')); %
ymax=0.035;
xs=ymax;
ny=101;
ys=linspace(-ymax,ymax,ny);
for i=1:ny
L1=sqrt((ys(i)-d/2).^2+D/2);
L2=sqrt((ys(i)+d/2).^2+D/2);
phi=2*pi*(L1-L2)/lambda;
% b(i,:)=4*cos(phi/2).^2; %每个元素的平方,
b(i,:)=4*cos(phi/2)^2; %整体的平方
end
figure(gcf);
nclevels=255;
br=(b/4.014)*nclevels;
% subplot(1,2,1)
% title('双缝干涉');
figure(1);
image(xs,ys,br);
colormap(gray(nclevels));
% subplot(1,2,2)
% plot(b(:),ys)
% --- Executes on button press in pushbutton2_DQ.
function pushbutton2_DQ_Callback(hObject, eventdata, handles)
f=0.2;
lambda=500*10^(-9);
% d=input('薄膜厚度='); d=0.00004;%薄膜厚度e-5量级
% theta=input('倾斜角度='); theta=0.8;%倾斜角度0.1-1
d=str2num(get(handles.DQ_hd,'string'));%获取
theta=str2num(get(handles.DQ_jd,'string'));%倾斜角度0.1-1
rMax=f*tan(theta/2);
N=501;
for i=1:N
x(i)=(i-1)*2*rMax/(N-1)-rMax;
for j=1:N
y(i)=(j-1)*2*rMax/(N-1)-rMax;
r(i,j)=sqrt(x(i)^2+y(i)^2);
delta(i,j)=2*d/sqrt(1+r(i,j)^2/f^2);
Phi(i,j)=2*pi*delta(i,j)/lambda;
B(i,j)=4*cos(Phi(i,j)/2)^2;
end
end
NCLevels=255;
Br=B/4*NCLevels;
% title('等倾干涉');
figure(2);
image(x,y,Br);
colormap(gray(NCLevels));
axis square;
% --- Executes on button press in pushbutton3_DH.
function pushbutton3_DH_Callback(hObject, eventdata, handles)
% lamda = 0.000632;
lamda = str2num(get(handles.lamada,'string'));
[X,Y] = meshgrid(-2:0.01:2);
for R=3200:-500:200
I=cos(pi/lamda*(X.^2+Y.^2)/(R)+pi/2);
% title('等厚干涉');
figure(3);
imshow(I) %将光强显示为灰度值
% pause(0.8)
end
三、运行结果
四、备注
1 matlab版本
2014a
2 参考文献
[1] 门云阁.MATLAB物理计算与可视化[M].清华大学出版社,2013.