📄 lab5.m
字号:
function [ret,x0,str,ts,xts]=lab5(t,x,u,flag);
%LAB5 is the M-file description of the SIMULINK system named LAB5.
% The block-diagram can be displayed by typing: LAB5.
%
% SYS=LAB5(T,X,U,FLAG) returns depending on FLAG certain
% system values given time point, T, current state vector, X,
% and input vector, U.
% FLAG is used to indicate the type of output to be returned in SYS.
%
% Setting FLAG=1 causes LAB5 to return state derivatives, FLAG=2
% discrete states, FLAG=3 system outputs and FLAG=4 next sample
% time. For more information and other options see SFUNC.
%
% Calling LAB5 with a FLAG of zero:
% [SIZES]=LAB5([],[],[],0), returns a vector, SIZES, which
% contains the sizes of the state vector and other parameters.
% SIZES(1) number of states
% SIZES(2) number of discrete states
% SIZES(3) number of outputs
% SIZES(4) number of inputs
% SIZES(5) number of roots (currently unsupported)
% SIZES(6) direct feedthrough flag
% SIZES(7) number of sample times
%
% For the definition of other parameters in SIZES, see SFUNC.
% See also, TRIM, LINMOD, LINSIM, EULER, RK23, RK45, ADAMS, GEAR.
% Note: This M-file is only used for saving graphical information;
% after the model is loaded into memory an internal model
% representation is used.
% the system will take on the name of this mfile:
sys = mfilename;
new_system(sys)
simver(1.3)
if (0 == (nargin + nargout))
set_param(sys,'Location',[182,110,596,422])
open_system(sys)
end;
set_param(sys,'algorithm', 'RK-45')
set_param(sys,'Start time', '0')
set_param(sys,'Stop time', '10')
set_param(sys,'Min step size', '0.0001')
set_param(sys,'Max step size', '0.1')
set_param(sys,'Relative error','1e-3')
set_param(sys,'Return vars', '')
add_block('built-in/Scope',[sys,'/','示波器'])
set_param([sys,'/','示波器'],...
'Font Size',11,...
'Vgain','2.000000',...
'Hgain','10.000000',...
'Vmax','4.000000',...
'Hmax','20.000000',...
'Window',[594,181,769,319])
open_system([sys,'/','示波器'])
set_param([sys,'/','示波器'],...
'Mask Display','',...
'position',[370,67,390,93])
% Subsystem ['Double click here',13,'to show bode plot ',13,'of controller'].
new_system([sys,'/',['Double click here',13,'to show bode plot ',13,'of controller']])
set_param([sys,'/',['Double click here',13,'to show bode plot ',13,'of controller']],'Location',[2,439,106,512])
set_param([sys,'/',['Double click here',13,'to show bode plot ',13,'of controller']],...
'Mask Display','Nyquist 图',...
'Mask Dialogue','eval(''nyquist1;'')')
% Finished composite block ['Double click here',13,'to show bode plot ',13,'of controller'].
set_param([sys,'/',['Double click here',13,'to show bode plot ',13,'of controller']],...
'ForeGround',4,...
'hide name',0,...
'Drop Shadow',4,...
'position',[180,165,260,201])
% Subsystem ['Double click here',13,'to show bode plot ',13,'of controller2'].
new_system([sys,'/',['Double click here',13,'to show bode plot ',13,'of controller2']])
set_param([sys,'/',['Double click here',13,'to show bode plot ',13,'of controller2']],'Location',[2,439,106,512])
set_param([sys,'/',['Double click here',13,'to show bode plot ',13,'of controller2']],...
'Mask Display','Nichols图',...
'Mask Dialogue','eval(''figure;nichols(N,D);grid;set(gcf,''''name'''',''''开环Nichols图'''');figure(gcf)'')')
% Finished composite block ['Double click here',13,'to show bode plot ',13,'of controller2'].
set_param([sys,'/',['Double click here',13,'to show bode plot ',13,'of controller2']],...
'ForeGround',4,...
'hide name',0,...
'Drop Shadow',4,...
'position',[290,165,370,201])
% Subsystem ['Double click here',13,'to show bode plot ',13,'of controller1'].
new_system([sys,'/',['Double click here',13,'to show bode plot ',13,'of controller1']])
set_param([sys,'/',['Double click here',13,'to show bode plot ',13,'of controller1']],'Location',[2,439,106,512])
set_param([sys,'/',['Double click here',13,'to show bode plot ',13,'of controller1']],...
'Mask Display','Bode图')
set_param([sys,'/',['Double click here',13,'to show bode plot ',13,'of controller1']],...
'Mask Dialogue','eval(''figure;[x,y,w]=bode(N,D);subplot(211); semilogx(w,20*log10(x));grid;subplot(212); semilogx(w,y(:,1));grid;subplot(111);set(gcf,''''name'''',''''开环伯德图'''');figure(gcf)'')')
% Finished composite block ['Double click here',13,'to show bode plot ',13,'of controller1'].
set_param([sys,'/',['Double click here',13,'to show bode plot ',13,'of controller1']],...
'ForeGround',4,...
'hide name',0,...
'Drop Shadow',4,...
'position',[70,225,145,261])
% Subsystem ['Double click here',13,'to start loading data',13,'and mu-syn design'].
new_system([sys,'/',['Double click here',13,'to start loading data',13,'and mu-syn design']])
set_param([sys,'/',['Double click here',13,'to start loading data',13,'and mu-syn design']],'Location',[2,439,106,512])
set_param([sys,'/',['Double click here',13,'to start loading data',13,'and mu-syn design']],...
'Mask Display','初始化',...
'Mask Dialogue','eval(''clc; clear all;N=[1] ; D=[1 1 0] ;printsys(N,D)'')')
% Finished composite block ['Double click here',13,'to start loading data',13,'and mu-syn design'].
set_param([sys,'/',['Double click here',13,'to start loading data',13,'and mu-syn design']],...
'ForeGround',4,...
'hide name',0,...
'Drop Shadow',4,...
'position',[70,165,145,201])
add_block('built-in/Transfer Fcn',[sys,'/','被控对象'])
set_param([sys,'/','被控对象'],...
'Font Size',11,...
'Numerator','N',...
'Denominator','D',...
'position',[205,65,265,95])
add_block('built-in/Step Fcn',[sys,'/','阶跃函数'])
set_param([sys,'/','阶跃函数'],...
'Font Size',11,...
'Time','0',...
'position',[35,65,55,85])
add_block('built-in/Sum',[sys,'/','加法器'])
set_param([sys,'/','加法器'],...
'Font Size',11,...
'inputs','+-',...
'position',[115,70,135,90])
% Subsystem ['Double click here',13,'to show bode plot',13,'of closed-loop3'].
new_system([sys,'/',['Double click here',13,'to show bode plot',13,'of closed-loop3']])
set_param([sys,'/',['Double click here',13,'to show bode plot',13,'of closed-loop3']],'Location',[2,439,106,512])
set_param([sys,'/',['Double click here',13,'to show bode plot',13,'of closed-loop3']],...
'Mask Display','闭环幅频特性')
set_param([sys,'/',['Double click here',13,'to show bode plot',13,'of closed-loop3']],...
'Mask Dialogue','eval(''[N1,D1]=cloop(N,D,-1); figure;[x,y,w]=bode(N1,D1);subplot(211); semilogx(w,x);grid; subplot(212); semilogx(w,y(:,1));grid;subplot(111);set(gcf,''''name'''',''''闭环幅相特性'''');figure(gcf)'')')
% Finished composite block ['Double click here',13,'to show bode plot',13,'of closed-loop3'].
set_param([sys,'/',['Double click here',13,'to show bode plot',13,'of closed-loop3']],...
'ForeGround',4,...
'hide name',0,...
'Drop Shadow',4,...
'position',[180,225,260,261])
add_block('built-in/Note',[sys,'/','频域分析窗口'])
set_param([sys,'/','频域分析窗口'],...
'ForeGround',4,...
'Font Size',16,...
'position',[210,10,215,15])
% Subsystem ['Double click here',13,'to show bode plot ',13,'of controller3'].
new_system([sys,'/',['Double click here',13,'to show bode plot ',13,'of controller3']])
set_param([sys,'/',['Double click here',13,'to show bode plot ',13,'of controller3']],'Location',[2,439,106,512])
set_param([sys,'/',['Double click here',13,'to show bode plot ',13,'of controller3']],...
'Mask Display','margin',...
'Mask Dialogue','eval(''[mag,phase,w]=bode(N,D);[GM,PM,Wg,Wc]=margin(mag,phase,w);GM=20*log10(GM),Wg,PM,Wc,'')')
% Finished composite block ['Double click here',13,'to show bode plot ',13,'of controller3'].
set_param([sys,'/',['Double click here',13,'to show bode plot ',13,'of controller3']],...
'ForeGround',4,...
'hide name',0,...
'Drop Shadow',4,...
'position',[290,225,370,261])
add_line(sys,[270,80;365,80])
add_line(sys,[60,75;110,75])
add_line(sys,[140,80;200,80])
add_line(sys,[270,80;320,80;320,125;85,125;85,85;110,85])
drawnow
% Return any arguments.
if (nargin | nargout)
% Must use feval here to access system in memory
if (nargin > 3)
if (flag == 0)
eval(['[ret,x0,str,ts,xts]=',sys,'(t,x,u,flag);'])
else
eval(['ret =', sys,'(t,x,u,flag);'])
end
else
[ret,x0,str,ts,xts] = feval(sys);
end
else
drawnow % Flash up the model and execute load callback
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -