基于Matlab app设计输入阻尼比和无阻尼自然频率输出标准二阶系统的响应函数的程序
时间: 2024-03-07 13:46:59 浏览: 63
好的,我可以为您提供一个基于 Matlab App 设计的程序,用于输入阻尼比和无阻尼自然频率,并输出标准二阶系统的响应函数。以下是程序的代码:
```matlab
function varargout = Standard2ndOrderSystem(varargin)
% STANDARD2NDORDERSYSTEM MATLAB code for Standard2ndOrderSystem.fig
% STANDARD2NDORDERSYSTEM, by itself, creates a new STANDARD2NDORDERSYSTEM or raises the existing
% singleton*.
%
% H = STANDARD2NDORDERSYSTEM returns the handle to a new STANDARD2NDORDERSYSTEM or the handle to
% the existing singleton*.
%
% STANDARD2NDORDERSYSTEM('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in STANDARD2NDORDERSYSTEM.M with the given input arguments.
%
% STANDARD2NDORDERSYSTEM('Property','Value',...) creates a new STANDARD2NDORDERSYSTEM or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before Standard2ndOrderSystem_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to Standard2ndOrderSystem_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 Standard2ndOrderSystem
% Last Modified by GUIDE v2.5 04-May-2021 15:05:38
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @Standard2ndOrderSystem_OpeningFcn, ...
'gui_OutputFcn', @Standard2ndOrderSystem_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 Standard2ndOrderSystem is made visible.
function Standard2ndOrderSystem_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 Standard2ndOrderSystem (see VARARGIN)
% Choose default command line output for Standard2ndOrderSystem
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes Standard2ndOrderSystem wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = Standard2ndOrderSystem_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;
% --- 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)
% get input values of damping ratio and natural frequency
damping_ratio = str2double(get(handles.edit1, 'String'));
natural_frequency = str2double(get(handles.edit2, 'String'));
% calculate response function
s = tf('s');
response_function = 1/(s^2 + 2*damping_ratio*natural_frequency*s + natural_frequency^2);
% display response function
set(handles.text4, 'String', char(response_function));
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)
% --- 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)
% --- 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
```
该程序是基于 Matlab App 设计的,包含两个输入框和一个输出框。在输入框中,您可以输入阻尼比和无阻尼自然频率的值。在点击“计算响应函数”按钮之后,程序将计算标准二阶系统的响应函数并在输出框中显示结果。
阅读全文