【光学】迈克尔逊实验仿真【含GUI Matlab源码 060期】

【光学】迈克尔逊实验仿真【含GUI Matlab源码 060期】_第1张图片

⛄一、获取代码方式

获取代码方式1:
完整代码已上传我的资源:【光学】基于matlab GUI迈克尔逊实验仿真【含Matlab源码 060期】
点击上面蓝色字体,直接付费下载,即可。

获取代码方式2:
付费专栏Matlab物理应用(初级版)

备注:
点击上面蓝色字体付费专栏Matlab物理应用(初级版),扫描上面二维码,付费29.9元订阅海神之光博客付费专栏Matlab物理应用(初级版),凭支付凭证,私信博主,可免费获得1份本博客上传CSDN资源代码(有效期为订阅日起,三天内有效);
点击CSDN资源下载链接:1份本博客上传CSDN资源代码

⛄二、部分源代码

function varargout = michelson_GUI(varargin)
% MICHELSON_GUI MATLAB code for michelson_GUI.fig
% MICHELSON_GUI, by itself, creates a new MICHELSON_GUI or raises the existing
% singleton*.
%
% H = MICHELSON_GUI returns the handle to a new MICHELSON_GUI or the handle to
% the existing singleton*.
%
% MICHELSON_GUI(‘CALLBACK’,hObject,eventData,handles,…) calls the local
% function named CALLBACK in MICHELSON_GUI.M with the given input arguments.
%
% MICHELSON_GUI(‘Property’,‘Value’,…) creates a new MICHELSON_GUI or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before michelson_GUI_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to michelson_GUI_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 michelson_GUI

% L

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct(‘gui_Name’, mfilename, …
‘gui_Singleton’, gui_Singleton, …
‘gui_OpeningFcn’, @michelson_GUI_OpeningFcn, …
‘gui_OutputFcn’, @michelson_GUI_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 michelson_GUI is made visible.
function michelson_GUI_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 michelson_GUI (see VARARGIN)

% Choose default command line output for michelson_GUI
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes michelson_GUI wait for user response (see UIRESUME)
% uiwait(handles.figure1);

% — Outputs from this function are returned to the command line.
function varargout = michelson_GUI_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
global lambda;
lambda = str2double(get(hObject, ‘String’))*10^(-9);

% — 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
global l;
l = str2double(get(hObject, ‘String’));

% — 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
global D;
D = str2double(get(hObject, ‘String’))*10^(-3);

% — 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

% — 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)
intensity0 = 1;
global D;
global l;
global lambda;
global beta;

global x;
global y;
global r;

xv = -0.1:0.001:0.1;
yv = -0.1:0.001:0.1;
[x, y] = meshgrid(xv, yv);
r = sqrt(x.^2 + y.^2);
beta = 0;

d2 = 0.5;
d1 = (d2-D)cos(beta);
d = d2-d1
cos(beta);

path1 = sqrt(x.^2 + y.2+l2);
path2 = sqrt((x-2d1sin(beta)).^2 + y.^2 + (l-2*d)^2);
opticalPath = abs(path1-path2);
sigma = 2 * pi() * opticalPath / lambda;
intensity = 4 * intensity0 * (cos(sigma / 2)).^2;

fig = surf(handles.axes3, x, y, intensity);
set(fig, ‘edgecolor’, ‘none’);
view(2);
caxis([0,4]);
colormap(gray);

% — Executes during object creation, after setting all properties.
function axes3_CreateFcn(hObject, eventdata, handles)
% hObject handle to axes3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

% Hint: place code in OpeningFcn to populate axes3

% — 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)
intensity0 = 1;

⛄三、运行结果

在这里插入图片描述
在这里插入图片描述

⛄四、matlab版本及参考文献

1 matlab版本
2014a

2 参考文献
[1] 门云阁.MATLAB物理计算与可视化[M].清华大学出版社,2013.

3 备注
简介此部分摘自互联网,仅供参考,若侵权,联系删除

你可能感兴趣的:(Matlab物理应用(初级版),matlab)