【物理应用】基于Matlab模拟杨氏双孔干涉实验

简介: 【物理应用】基于Matlab模拟杨氏双孔干涉实验

 ✅作者简介:热爱科研的Matlab仿真开发者,修心和技术同步精进,matlab项目合作可私信。

🍎个人主页:Matlab科研工作室

🍊个人信条:格物致知。

更多Matlab仿真内容点击👇

智能优化算法神经网络预测雷达通信 无线传感器

信号处理图像处理路径规划元胞自动机无人机

1 内容介绍

根据光的双缝干涉实验理论,利用MATLAB编写程序对双缝干涉实验进行模拟,绘制出双缝干涉的图样和光强分布曲线,并且同步计算出相应的条纹间距和对比度,直观地展现了单色光的双缝干涉这一物理现象,实验结果与实际计算结果一致,为双缝干涉的理论与实验提供了有效的支持.

2 部分代码

function varargout = ganshe(varargin)

% GANSHE M-file for ganshe.fig

%      GANSHE, by itself, creates a new GANSHE or raises the existing

%      singleton*.

%

%      H = GANSHE returns the handle to a new GANSHE or the handle to

%      the existing singleton*.

%

%      GANSHE('CALLBACK',hObject,eventData,handles,...) calls the local

%      function named CALLBACK in GANSHE.M with the given input arguments.

%

%      GANSHE('Property','Value',...) creates a new GANSHE or raises the

%      existing singleton*.  Starting from the left, property value pairs are

%      applied to the GUI before ganshe_OpeningFcn gets called.  An

%      unrecognized property name or invalid value makes property application

%      stop.  All inputs are passed to ganshe_OpeningFcn via varargin.

%

%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one

%      instance to run (singleton)".

%

% See also: GUIDE, GUIDATA, GUIHANDLES

% Edit the above text to modify the response to help ganshe

% Last Modified by GUIDE v2.5 21-Jun-2014 11:31:04

% Begin initialization code - DO NOT EDIT

gui_Singleton = 1;

gui_State = struct('gui_Name',       mfilename, ...

                  'gui_Singleton',  gui_Singleton, ...

                  'gui_OpeningFcn', @ganshe_OpeningFcn, ...

                  'gui_OutputFcn',  @ganshe_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 ganshe is made visible.

function ganshe_OpeningFcn(hObject, eventdata, handles, varargin)

% This function has no output args, see OutputFcn.

% hObject    handle to figure

% eventdata  reserved - to be defined in a future version of MATLAB

% handles    structure with handles and user data (see GUIDATA)

% varargin   command line arguments to ganshe (see VARARGIN)

% Choose default command line output for ganshe

handles.output = hObject;

% Update handles structure

guidata(hObject, handles);

% UIWAIT makes ganshe wait for user response (see UIRESUME)

% uiwait(handles.figure1);

% --- Outputs from this function are returned to the command line.

function varargout = ganshe_OutputFcn(hObject, eventdata, handles)

% varargout  cell array for returning output args (see VARARGOUT);

% hObject    handle to figure

% eventdata  reserved - to be defined in a future version of MATLAB

% handles    structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure

varargout{1} = handles.output;

function edit1_Callback(hObject, eventdata, handles)

% hObject    handle to edit1 (see GCBO)

% eventdata  reserved - to be defined in a future version of MATLAB

% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit1 as text

%        str2double(get(hObject,'String')) returns contents of edit1 as a double

% --- Executes during object creation, after setting all properties.

function edit1_CreateFcn(hObject, eventdata, handles)

% hObject    handle to edit1 (see GCBO)

% eventdata  reserved - to be defined in a future version of MATLAB

% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.

%       See ISPC and COMPUTER.

if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))

   set(hObject,'BackgroundColor','white');

end

function edit2_Callback(hObject, eventdata, handles)

% hObject    handle to edit2 (see GCBO)

% eventdata  reserved - to be defined in a future version of MATLAB

% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit2 as text

%        str2double(get(hObject,'String')) returns contents of edit2 as a double

% --- Executes during object creation, after setting all properties.

function edit2_CreateFcn(hObject, eventdata, handles)

% hObject    handle to edit2 (see GCBO)

% eventdata  reserved - to be defined in a future version of MATLAB

% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.

%       See ISPC and COMPUTER.

if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))

   set(hObject,'BackgroundColor','white');

end

function edit3_Callback(hObject, eventdata, handles)

% hObject    handle to edit3 (see GCBO)

% eventdata  reserved - to be defined in a future version of MATLAB

% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit3 as text

%        str2double(get(hObject,'String')) returns contents of edit3 as a double

% --- Executes during object creation, after setting all properties.

function edit3_CreateFcn(hObject, eventdata, handles)

% hObject    handle to edit3 (see GCBO)

% eventdata  reserved - to be defined in a future version of MATLAB

% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.

%       See ISPC and COMPUTER.

if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))

   set(hObject,'BackgroundColor','white');

end

function edit4_Callback(hObject, eventdata, handles)

% hObject    handle to edit4 (see GCBO)

% eventdata  reserved - to be defined in a future version of MATLAB

% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit4 as text

%        str2double(get(hObject,'String')) returns contents of edit4 as a double

% --- Executes during object creation, after setting all properties.

function edit4_CreateFcn(hObject, eventdata, handles)

% hObject    handle to edit4 (see GCBO)

% eventdata  reserved - to be defined in a future version of MATLAB

% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.

%       See ISPC and COMPUTER.

if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))

   set(hObject,'BackgroundColor','white');

% --- Executes during object creation, after setting all properties.

function edit6_CreateFcn(hObject, eventdata, handles)

% hObject    handle to edit6 (see GCBO)

% eventdata  reserved - to be defined in a future version of MATLAB

% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.

%       See ISPC and COMPUTER.

if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))

   set(hObject,'BackgroundColor','white');

end

function edit7_Callback(hObject, eventdata, handles)

% hObject    handle to edit7 (see GCBO)

% eventdata  reserved - to be defined in a future version of MATLAB

% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit7 as text

%        str2double(get(hObject,'String')) returns contents of edit7 as a double

% --- Executes during object creation, after setting all properties.

function edit7_CreateFcn(hObject, eventdata, handles)

% hObject    handle to edit7 (see GCBO)

% eventdata  reserved - to be defined in a future version of MATLAB

% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.

%       See ISPC and COMPUTER.

if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))

   set(hObject,'BackgroundColor','white');

end

function edit8_Callback(hObject, eventdata, handles)

% hObject    handle to edit8 (see GCBO)

% eventdata  reserved - to be defined in a future version of MATLAB

% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit8 as text

%        str2double(get(hObject,'String')) returns contents of edit8 as a double

% --- Executes during object creation, after setting all properties.

function edit8_CreateFcn(hObject, eventdata, handles)

% hObject    handle to edit8 (see GCBO)

% eventdata  reserved - to be defined in a future version of MATLAB

% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.

%       See ISPC and COMPUTER.

if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))

   set(hObject,'BackgroundColor','white');

end

function edit9_Callback(hObject, eventdata, handles)

% hObject    handle to edit9 (see GCBO)

% eventdata  reserved - to be defined in a future version of MATLAB

% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit9 as text

%        str2double(get(hObject,'String')) returns contents of edit9 as a double

% --- Executes during object creation, after setting all properties.

function edit9_CreateFcn(hObject, eventdata, handles)

% hObject    handle to edit9 (see GCBO)

% eventdata  reserved - to be defined in a future version of MATLAB

% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.

%       See ISPC and COMPUTER.

if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))

   set(hObject,'BackgroundColor','white');

end

% --- Executes on button press in pushbutton1.

function pushbutton1_Callback(hObject, eventdata, handles)

% hObject    handle to pushbutton1 (see GCBO)

% eventdata  reserved - to be defined in a future version of MATLAB

% handles    structure with handles and user data (see GUIDATA)

%读入实验参数

lambda=str2num(get(handles.edit1,'string'))*1e-9;  %读入波长

d=str2num(get(handles.edit2,'string'))*1e-3;       %读入孔距

D=str2num(get(handles.edit3,'string'));            %读入观察屏距离

%读入观察范围参数

xa=str2num(get(handles.edit4,'string'));     %最小的横坐标值

xb=str2num(get(handles.edit5,'string'));     %最大的横坐标值

n1=str2num(get(handles.edit6,'string'));     %x方向等分份数

ya=str2num(get(handles.edit7,'string'));     %最小的纵坐标值

yb=str2num(get(handles.edit8,'string'));     %最大的纵坐标值

n2=str2num(get(handles.edit9,'string'));     %y方向等分份数

k=2*pi/lambda;          %计算波数

x=linspace(xa,xb,n1);   %x坐标

y=linspace(ya,yb,n2);   %y坐标

[x,y]=meshgrid(x,y);

r1=sqrt((x-d/2).^2+y.^2+D^2);

r2=sqrt((x+d/2).^2+y.^2+D^2);

I=(cos(k*r1)./r1+cos(k*r2)./r2).^2+(sin(k*r1)./r1+sin(k*r2)./r2).^2;

I=I/(max(max(I)));

I=I*255;

axes(handles.axes1)

x=linspace(xa,xb,n1);

y=linspace(ya,yb,n2);

image(x,y,I)

colormap(gray(255))

xlabel('x (m)')

ylabel('y (m)')

title('杨氏双孔干涉条纹')

% --- Executes on button press in pushbutton2.

function pushbutton2_Callback(hObject, eventdata, handles)

% hObject    handle to pushbutton2 (see GCBO)

% eventdata  reserved - to be defined in a future version of MATLAB

% handles    structure with handles and user data (see GUIDATA)

% --- Executes on button press in pushbutton3.

function pushbutton3_Callback(hObject, eventdata, handles)

% hObject    handle to pushbutton3 (see GCBO)

% eventdata  reserved - to be defined in a future version of MATLAB

% handles    structure with handles and user data (see GUIDATA)

3 运行结果

image.gif编辑

image.gif编辑

4 参考文献

[1]盛虹. 基于MATLAB的杨氏双缝干涉实验模拟[J]. 河南科学, 2010, 28(6):3.

博主简介:擅长智能优化算法神经网络预测信号处理元胞自动机图像处理路径规划无人机雷达通信无线传感器等多种领域的Matlab仿真,相关matlab代码问题可私信交流。

部分理论引用网络文献,若有侵权联系博主删除。


相关文章
|
机器学习/深度学习 监控 数据可视化
MATLAB应用指导:利用MATLAB进行内部局域网管理软件的数据分析和可视化
在今天的数字化时代,内部局域网管理软件在各种组织中起着至关重要的作用。这些软件可以监控网络活动,收集大量的数据,但数据的真正价值在于如何分析和可视化它。在本文中,我们将探讨如何使用MATLAB进行内部局域网管理软件的数据分析和可视化,以帮助您更好地理解和优化您的网络。
370 0
|
机器学习/深度学习 传感器 算法
【物理应用】基于FVM实现瞬态对流扩散附matlab代码
【物理应用】基于FVM实现瞬态对流扩散附matlab代码
|
24天前
|
传感器 机器学习/深度学习 运维
一种欠定盲源分离方法及其在模态识别中的应用(Matlab代码实现)
一种欠定盲源分离方法及其在模态识别中的应用(Matlab代码实现)
|
21天前
|
5G Python
选择合并应用于差分放大转发中继在瑞利衰落信道上的通信系统研究(Matlab代码实现)
选择合并应用于差分放大转发中继在瑞利衰落信道上的通信系统研究(Matlab代码实现)
|
7月前
|
机器学习/深度学习 数据采集 人工智能
MATLAB在机器学习模型训练与性能优化中的应用探讨
本文介绍了如何使用MATLAB进行机器学习模型的训练与优化。MATLAB作为强大的科学计算工具,提供了丰富的函数库和工具箱,简化了数据预处理、模型选择、训练及评估的过程。文章详细讲解了从数据准备到模型优化的各个步骤,并通过代码实例展示了SVM等模型的应用。此外,还探讨了超参数调优、特征选择、模型集成等优化方法,以及深度学习与传统机器学习的结合。最后,介绍了模型部署和并行计算技巧,帮助用户高效构建和优化机器学习模型。
MATLAB在机器学习模型训练与性能优化中的应用探讨
|
7月前
|
算法
MATLAB在风险管理中的应用:从VaR计算到压力测试
本文介绍如何使用MATLAB进行风险管理,涵盖风险度量(如VaR)、压力测试和风险分解。通过历史模拟法、参数法和蒙特卡洛模拟法计算VaR,评估投资组合在极端市场条件下的表现,并通过边际VaR和成分VaR识别风险来源。结合具体案例和代码实现,帮助读者掌握MATLAB在风险管理中的应用,确保投资组合的稳健性。
|
7月前
|
数据建模 数据处理
MATLAB学习之旅:数据建模与仿真应用
在MATLAB的学习中,我们已掌握基础操作、数据处理与统计分析。接下来将进入数据建模与仿真应用阶段,学习如何构建和验证现实世界的模型。我们将从定义模型结构和参数入手,涵盖线性回归、动态系统建模等内容,并通过仿真和实际数据对比评估模型的准确性和可靠性。最终,这些技能将帮助我们在科学研究和工程应用中解决复杂问题。
二阶锥松弛在配电网最优潮流计算中的应用matlab
二阶锥松弛在配电网最优潮流计算中的应用matlab
|
机器学习/深度学习 编解码 监控
探索MATLAB在计算机视觉与深度学习领域的实战应用
探索MATLAB在计算机视觉与深度学习领域的实战应用
|
算法 安全 数据挖掘
随机数生成方法及其在Matlab中的应用
随机数生成方法及其在Matlab中的应用

热门文章

最新文章