【物理应用】基于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进行内部局域网管理软件的数据分析和可视化,以帮助您更好地理解和优化您的网络。
273 0
|
机器学习/深度学习 传感器 算法
【物理应用】基于FVM实现瞬态对流扩散附matlab代码
【物理应用】基于FVM实现瞬态对流扩散附matlab代码
二阶锥松弛在配电网最优潮流计算中的应用matlab
二阶锥松弛在配电网最优潮流计算中的应用matlab
|
5月前
|
算法 安全 数据挖掘
随机数生成方法及其在Matlab中的应用
随机数生成方法及其在Matlab中的应用
|
6月前
|
算法 数据可视化 数据挖掘
MATLAB中常用的数学函数及其应用示例
MATLAB中常用的数学函数及其应用示例
|
7月前
|
机器学习/深度学习 编解码 监控
探索MATLAB在计算机视觉与深度学习领域的实战应用
探索MATLAB在计算机视觉与深度学习领域的实战应用
92 7
|
7月前
|
SQL 移动开发 算法
MATLAB改进模糊C均值聚类FCM在电子商务信用评价应用:分析淘宝网店铺数据|数据分享
MATLAB改进模糊C均值聚类FCM在电子商务信用评价应用:分析淘宝网店铺数据|数据分享
|
7月前
|
JavaScript 编译器 API
MATLAB实战 | S函数的设计与应用
S函数用于开发新的Simulink通用功能模块,是一种对模块库进行扩展的工具。S函数可以采用MATLAB语言、C、C++、FORTRAN、Ada等语言编写。在S函数中使用文本方式输入公式、方程,非常适合复杂动态系统的数学描述,并且在仿真过程中可以对仿真进行更精确的控制。
128 0
MATLAB实战 | S函数的设计与应用
|
算法 C语言
【数学建模系列】TOPSIS法的算法步骤及实战应用——MATLAB实现
客观评价方法中的一种,亦称为理想解法,是一种有效的多指标评价方法。这种方法通过构造评价问题的正理想解和负理想解,即各指标的最优解和最劣解,通过计算每个方案到理想方案的相对贴近度,即靠近止理想解和远离负理想解的程度,来对方案进行排序,从而选出最优方案。
【数学建模系列】TOPSIS法的算法步骤及实战应用——MATLAB实现
|
机器学习/深度学习 传感器 安全
基于matlab模拟FMCW毫米波高度测量雷达对于无人机的应用
基于matlab模拟FMCW毫米波高度测量雷达对于无人机的应用