求助matlab的远程序

求助matlab的远程序,第1张

求助matlab的远滑中简程序

function varargout = a1(varargin)

% A1 M-file for a1.fig

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

% singleton*.

%

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

% the existing singleton*.

%

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

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

%

% A1('Property','信裤Value',...) creates a new A1 or raises the

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

% applied to the GUI before a1_OpeningFunction gets called. An

% unrecognized property name or invalid value makes property application

% stop. All inputs are passed to a1_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

% Copyright 2002-2003 The MathWorks, Inc.

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

% Last Modified by GUIDE v2.5 08-Dec-2003 14:47:39

% Begin initialization code - DO NOT EDIT

gui_Singleton = 1

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

'gui_Singleton', gui_Singleton, ...

'gui_OpeningFcn', @a1_OpeningFcn, ...

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

function a1_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 a1 (see VARARGIN)

% Choose default command line output for a1

handles.output = hObject

% Update handles structure

guidata(hObject, handles)

% This sets up the initial plot - only do when we are invisible

% so window can get raised using a1.

if strcmp(get(hObject,'Visible'),'off')

ezplot('sin(x)/x')

text(0,1,'y=sin(x)/x')

end

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

% uiwait(handles.figure1)

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

function varargout = a1_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)

axes(handles.axes1)

cla

popup_sel_index = get(handles.popupmenu1, 'Value')

switch popup_sel_index

case 1

ezplot('sin(x)/x')

text(0,1,'y=sin(x)/x')

case 2

ezplot('sin(x)')

text([-1.5*pi,0.5*pi],[1 1],'y=sin(x)')

end

% --------------------------------------------------------------------

function FileMenu_Callback(hObject, eventdata, handles)

% hObject handle to FileMenu (see GCBO)

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

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

% --------------------------------------------------------------------

function OpenMenuItem_Callback(hObject, eventdata, handles)

% hObject handle to OpenMenuItem (see GCBO)

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

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

file = uigetfile('*.fig')

if ~isequal(file, 0)

open(file)

end

% --------------------------------------------------------------------

function PrintMenuItem_Callback(hObject, eventdata, handles)

% hObject handle to PrintMenuItem (see GCBO)

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

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

printdlg(handles.figure1)

% --------------------------------------------------------------------

function CloseMenuItem_Callback(hObject, eventdata, handles)

% hObject handle to CloseMenuItem (see GCBO)

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

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

selection = questdlg(['Close ' get(handles.figure1,'Name') '?'],...

['Close ' get(handles.figure1,'Name') '...'],...

'Yes','No','Yes')

if strcmp(selection,'No')

return

end

delete(handles.figure1)

% --- Executes on selection change in popupmenu1.

function popupmenu1_Callback(hObject, eventdata, handles)

% hObject handle to popupmenu1 (see GCBO)

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

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

% Hints: contents = get(hObject,'String') returns popupmenu1 contents as cell array

% contents{get(hObject,'Value')} returns selected item from popupmenu1

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

function popupmenu1_CreateFcn(hObject, eventdata, handles)

% hObject handle to popupmenu1 (see GCBO)

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

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

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

% See ISPC and COMPUTER.

if ispc

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

else

set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'))

end

set(hObject, 'String', {'ezplot(sin(x)/x))', 'ezplot(sin(x))'})

1.理解连续系统时域分析方法.

2.学习利用matlab对连续系统进行时域分析的方法.

3.掌握单位冲激响应和单位阶跃响应一般求解方法和基本特征,学习利用matlab求此响应的方法。

4.掌握单位冲激响应与系统稳定性、因果性之间的关系。

二、实验器材

计算机、MATLAB软件

三、实验原理

对于单输入-单输出系统的输入激励为 f (t),输出响应为y(t),则描述连续LTI系统的数学模型为n阶次的常系数线性微分方程,形式如下

[图片上传失败...(image-82e2d0-1639285196529)] (3-1)

式子中, a i = 0,1,...n,和b i =0,1,...m均为常数。

由信号与系统的分析理论值,如果描述系统的微分方程、激励和初始状态已知,我们可用经典时域求解法求出其解。但对于高阶系统,手工计算十分的繁琐,甚至很困难,这时可以用matlab工具求解。

Matlab里提供了求(3-1)解用到的函数,常用的是impluse()、step()、lism()、conv()、dsolve()。下面我们分别介绍这几个函数。

1.****连续时间系统冲激响应扮纳桥和阶跃响应的求解

连续LTI系统的冲激响应和阶跃响应,分别用impluse和step求解。其调用格式为

impluse (b,a) y=impluse(sys,t)

step (b,a) y=step(sys,t)

式中,t表示计算系统响应的抽样点向量,sys是LTI系统模型,它表示 微分方程,差分方程或状态方程 。其调用格式

sys = tf (b,a)

式中,b和a分别是微分方程的右端和左端系数向量。例如

[图片上传失败...(image-63fd93-1639285196529)]

用a=[a3,a2,a1,a0] b=[b3,b2,b1,b0] ,sys = tf (b,a) 获得其LTI模型。

例1****:已知描述某连续系统的微分方程为

[图片上传失败...(image-954b31-1639285196529)]

试利用matlab****绘出该系统厅猛的单位冲激响应和单位阶跃响应的时域波形,并根据单位冲激响应判断系统的稳定性和因果性。`1

matlab程序如下

a=[1 1 6]

b=[1]

subplot(2,1,1)

impulse(b,a)

subplot(2,1,2)

step(b,a)

程序运行后,其图形如下3-1所示。

[图片上传失败...(image-8ac458-1639285196530)]

图****3-1 系统的冲激响应和阶跃响应图

从图3-1所示的系统的单位冲激响应的时域波形可以看出,当时间t<0时系统的单位冲激响应h(t)=0,所以该系统为因果系统;同时h(t)随着时间的增长而衰减,当t趋于无穷大时时,h(t)趋于零,所以系统也是一个稳定的系统。

2.****连续时间系统零输入响应的求解

在MATLAB中,initial是求连续系统的零输入响应函数,其调用形式为

initial(sys,x0)

[y,x,t]=initial(sys,x0)

initial函数可计算出连续时间线性系统由于初始状态所引起的响应(故而称零输入响应)。当不带输出变量引用函数时,initial函数在当前图形窗茄手口中直接绘制出系统的零输入响应。

例2****:已知描述某连续系统的微分方程为

[图片上传失败...(image-15bccf-1639285196529)]

y(0)=1,y’(0)=2, 用matlab****求其零输入响应

程序如下:

a=[1 1 6]

b=[1]

sys=tf(b,a)

sys1=ss(sys)% 转成状态变量表示

x0=[1,2]

initial(sys1,x0)

运行结果如图3-2所示

[图片上传失败...(image-f08768-1639285196530)]

图****3-2 系统的零输入响应图

3.****连续时间系统零状态响应的数值计算----- lism()

求解微分方程零状态响应的数值解。其调用格式主要有两种。

**lism(sys,f,t) y=lism(sys,f,t) **

其中,f是输入信号在向量t定义的时间点上的采样值,t是输入信号时间范围向量,sys是LTI系统模型

例3****: 已知描述某连续系统的微分方程为

[图片上传失败...(image-4a9e83-1639285196529)]

试利用matlab求出该系统当激励信号为[图片上传失败...(image-5ad649-1639285196529)] 时,系统的响应[图片上传失败...(image-348322-1639285196529)] ,并会出其波形。

matlab程序如下

a=[1 2 1]

b=[1 2]

sys=tf(b,a)%定义系统函数对象

p=0.01%定义采样时间间隔

t=0:p:5

f=exp(-2*t)

lsim(sys,f,t)%对系统输出信号进行仿真

程序运行后,其图形如图3-3所示。

[图片上传失败...(image-3950ed-1639285196529)]

图3-3 连续系统的响应仿真

4.****微分方程的符号解的函数dsolve()

在MATLAB中,dsolve()是求解微分方程的符号解的函数,其调用形式为

r=dsolve(‘eq1,eq2,…’,’cond1,cond2,…’,’v’)

或r=dsolve(‘eq1’,eq2’,…,’cond1’,’cond2’,…,’v’)

其中cond1、cond2….是初始条件(如没有给出初始条件,则默认为求通解),v为自变量变量。D表示一阶微分,D2为二阶微分……。函数dsolve把D后的变量当成因变量,默认为这些变量对自变量的求导。

例****4****:求二阶系统[图片上传失败...(image-9ca77c-1639285196529)] 在初始条件[图片上传失败...(image-ae497b-1639285196529)] 下的零输入响应的解、零状态响应的解及全解

matlab程序如下

yzi=dsolve('D2y+5 Dy+4 y=0','y(0)=0,Dy(0)=1')

yzs=dsolve('D2y+5 Dy+4 y=exp(-3*t)','y(0)=0,Dy(0)=0')

y=dsolve('D2y+5 Dy+4 y=exp(-3*t)','y(0)=0,Dy(0)=1')

运行结果如下

yzi =

-1/3 exp(-4 t)+1/3*exp(-t)

yzs =

1/3 exp(-4 t)+1/6 exp(-t)-1/2 exp(-3*t)

y =

1/2 exp(-t)-1/2 exp(-3*t)

即 [图片上传失败...(image-8a13eb-1639285196529)]

[图片上传失败...(image-9036d5-1639285196529)]

[图片上传失败...(image-fa7bd7-1639285196529)]

四、实验内容

1.验证实验原理中所述的相关程序

2.已知描述某连续系统的微分方程为

[图片上传失败...(image-d41f06-1639285196529)]

(1) 试利用matlab绘出该系统的冲激响应和阶跃响应的时域波形,并根据冲激响应判断系统的稳定性。

a=[1,3,2]

b=[1,2]

subplot(2,1,1)

impulse(b,a)

subplot(2,1,2)

step(b,a)

wending

(2) 当激励信号为[图片上传失败...(image-e16660-1639285196529)] 时,系统的零状态响应[图片上传失败...(image-5beb2d-1639285196529)] ,并绘出响应的波形。

a=[1,3,2]

b=[1,2]

sys=tf(b,a)

t=0:0.01:5

f=exp(-2*t)

lsim(sys,f,t)

3.求三阶系统[图片上传失败...(image-a71fa6-1639285196529)] 在初始条件[图片上传失败...(image-40502a-1639285196529)] 下的零输入响应的解、零状态响应的解及全解。

yzi=dsolve('D2y+5*Dy+y=0','y(0)=0,Dy(0)=1')

yzs=dsolve('D2y+5 Dy+y=exp(-3 t)','y(0)=0,Dy(0)=0')

y=dsolve('D2y+5 Dy+y=exp(-3 t)','y(0)=0,Dy(0)=1')

五、实验报告要求

1.实验内容中详细说明用连续系统时域分析法的步骤与原理。

2.写出其对应的matlab程序。

3.上机调试程序的方法及实验中的心得体会。


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/12357187.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-24
下一篇 2023-05-24

发表评论

登录后才能评论

评论列表(0条)

保存