📄 lab04.m
字号:
function [ret,x0,str,ts,xts]=lab04(t,x,u,flag);
%LAB04 is the M-file description of the SIMULINK system named LAB04.
% The block-diagram can be displayed by typing: LAB04.
%
% SYS=LAB04(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 LAB04 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 LAB04 with a FLAG of zero:
% [SIZES]=LAB04([],[],[],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',[14,121,133,515])
open_system(sys)
end;
set_param(sys,'algorithm', 'RK-45')
set_param(sys,'Start time', '0.0')
set_param(sys,'Stop time', '10')
set_param(sys,'Min step size', '0.0001')
set_param(sys,'Max step size', '0.01')
set_param(sys,'Relative error','1e-3')
set_param(sys,'Return vars', '')
% Subsystem '死区特性'.
new_system([sys,'/','死区特性'])
set_param([sys,'/','死区特性'],'Location',[45,261,245,359])
add_block('built-in/Outport',[sys,'/','死区特性/out_1'])
set_param([sys,'/','死区特性/out_1'],...
'position',[175,40,195,60])
add_block('built-in/Inport',[sys,'/','死区特性/in_1'])
set_param([sys,'/','死区特性/in_1'],...
'position',[10,40,30,60])
add_block('built-in/Gain',[sys,'/','死区特性/Gain'])
set_param([sys,'/','死区特性/Gain'],...
'Gain','K_dz',...
'position',[130,40,150,60])
add_block('built-in/Dead Zone',[sys,'/','死区特性/Dead Zone'])
set_param([sys,'/','死区特性/Dead Zone'],...
'Lower_value','-a',...
'Upper_value','a',...
'position',[70,40,95,60])
add_line([sys,'/','死区特性'],[100,50;125,50])
add_line([sys,'/','死区特性'],[155,50;170,50])
add_line([sys,'/','死区特性'],[35,50;65,50])
set_param([sys,'/','死区特性'],...
'Mask Display','plot(0,0,100,100,[87,9],[50,50],[50,50],[10,91],[80,60],[80,50],[20,40],[20,50])',...
'Mask Dialogue','死区特性的宽度和斜率:|宽度a:|斜率K:',...
'Mask Translate','a=@1;K_dz=@2;')
set_param([sys,'/','死区特性'],...
'Mask Entries','0.5\/1\/')
% Finished composite block '死区特性'.
set_param([sys,'/','死区特性'],...
'position',[35,42,70,78])
% Subsystem '饱和特性'.
new_system([sys,'/','饱和特性'])
set_param([sys,'/','饱和特性'],'Location',[-15,11207045,140,11207155])
add_block('built-in/Outport',[sys,'/','饱和特性/out_1'])
set_param([sys,'/','饱和特性/out_1'],...
'position',[165,60,185,80])
add_block('built-in/Inport',[sys,'/','饱和特性/in_1'])
set_param([sys,'/','饱和特性/in_1'],...
'position',[5,60,25,80])
add_block('built-in/Gain',[sys,'/','饱和特性/Gain'])
set_param([sys,'/','饱和特性/Gain'],...
'Gain','K_s',...
'position',[115,60,135,80])
add_block('built-in/Saturation',[sys,'/','饱和特性/Saturation'])
set_param([sys,'/','饱和特性/Saturation'],...
'Lower Limit','-c',...
'Upper Limit','c',...
'position',[50,60,75,80])
add_line([sys,'/','饱和特性'],[140,70;160,70])
add_line([sys,'/','饱和特性'],[30,70;45,70])
add_line([sys,'/','饱和特性'],[80,70;110,70])
set_param([sys,'/','饱和特性'],...
'Mask Display','plot(0,0,100,100,[89,7],[50,50],[49,49],[11,90],[87,66,32,13],[70,70,30,30])',...
'Mask Dialogue','饱和特性的宽度和斜率:|宽度(a):|斜率K:',...
'Mask Translate','c=@1;K_s=@2;')
set_param([sys,'/','饱和特性'],...
'Mask Entries','0.5\/1\/')
% Finished composite block '饱和特性'.
set_param([sys,'/','饱和特性'],...
'position',[35,105,70,145])
% Subsystem '间隙特性'.
new_system([sys,'/','间隙特性'])
set_param([sys,'/','间隙特性'],'Location',[75,186,262,324])
add_block('built-in/Backlash',[sys,'/','间隙特性/Backlash'])
set_param([sys,'/','间隙特性/Backlash'],...
'Backlash width','b',...
'Mask Display','',...
'position',[65,50,90,70])
add_block('built-in/Gain',[sys,'/','间隙特性/Gain'])
set_param([sys,'/','间隙特性/Gain'],...
'Gain','K_bl',...
'position',[120,50,140,70])
add_block('built-in/Outport',[sys,'/','间隙特性/out_1'])
set_param([sys,'/','间隙特性/out_1'],...
'position',[160,50,180,70])
add_block('built-in/Inport',[sys,'/','间隙特性/in_1'])
set_param([sys,'/','间隙特性/in_1'],...
'position',[10,50,30,70])
add_line([sys,'/','间隙特性'],[145,60;155,60])
add_line([sys,'/','间隙特性'],[95,60;115,60])
add_line([sys,'/','间隙特性'],[35,60;60,60])
set_param([sys,'/','间隙特性'],...
'Mask Display','plot(0,0,100,100,[89,7],[50,50],[50,50],[7,93],[40,20,60,80,40],[21,21,80,80,21])',...
'Mask Dialogue','间隙特性的宽度和斜率:|宽度b:|斜率K:',...
'Mask Translate','b=@1;K_bl=@2;')
set_param([sys,'/','间隙特性'],...
'Mask Entries','0.5\/1\/')
% Finished composite block '间隙特性'.
set_param([sys,'/','间隙特性'],...
'position',[35,177,70,213])
add_block('built-in/Note',[sys,'/','非线性环节'])
set_param([sys,'/','非线性环节'],...
'ForeGround',4,...
'Font Size',14,...
'position',[55,10,60,15])
add_block('built-in/Look Up Table',[sys,'/','摩擦特性'])
set_param([sys,'/','摩擦特性'],...
'Input_Values','[-1,0,0,1]',...
'Output_Values','[-gain-ini -ini ini gain+ini]',...
'Mask Display','plot([-1 0 0 1],[-gain-ini, -ini, ini, gain+ini],[-1 1],[0 0],[0 0],[-x,x])')
set_param([sys,'/','摩擦特性'],...
'Mask Type','Coulombic Friction',...
'Mask Dialogue','摩擦阻力特性|静摩擦M:|增益K:',...
'Mask Translate','ini=@1;gain=@2;x=max(ini,gain+ini);')
set_param([sys,'/','摩擦特性'],...
'Mask Help','This block has a discontinuity\nat zero and a linear gain afterward.\ny= sign(x)*(Gain*abs(x)+Offset)',...
'Mask Entries','1\/1\/',...
'position',[35,311,70,349])
% Subsystem '继电特性'.
new_system([sys,'/','继电特性'])
set_param([sys,'/','继电特性'],'Location',[75,125,442,335])
add_block('built-in/Outport',[sys,'/','继电特性/out_1'])
set_param([sys,'/','继电特性/out_1'],...
'position',[330,115,350,135])
add_block('built-in/MATLAB Fcn',[sys,'/','继电特性/MATLAB Fcn'])
set_param([sys,'/','继电特性/MATLAB Fcn'],...
'MATLAB Fcn','relay',...
'Output Width','1',...
'position',[260,110,310,140])
add_block('built-in/Derivative',[sys,'/','继电特性/Derivative'])
set_param([sys,'/','继电特性/Derivative'],...
'position',[70,100,100,120])
add_block('built-in/Constant',[sys,'/','继电特性/Constant2'])
set_param([sys,'/','继电特性/Constant2'],...
'Value','val',...
'position',[140,105,160,125])
add_block('built-in/Constant',[sys,'/','继电特性/Constant'])
set_param([sys,'/','继电特性/Constant'],...
'Value','m',...
'position',[140,75,160,95])
add_block('built-in/Constant',[sys,'/','继电特性/Constant1'])
set_param([sys,'/','继电特性/Constant1'],...
'Value','h',...
'position',[145,45,165,65])
add_block('built-in/Mux',[sys,'/','继电特性/Mux'])
set_param([sys,'/','继电特性/Mux'],...
'inputs','5',...
'position',[205,81,240,169])
add_block('built-in/Inport',[sys,'/','继电特性/in_1'])
set_param([sys,'/','继电特性/in_1'],...
'position',[15,145,35,165])
add_line([sys,'/','继电特性'],[165,85;175,85;175,110;200,110])
add_line([sys,'/','继电特性'],[245,125;255,125])
add_line([sys,'/','继电特性'],[40,155;200,155])
add_line([sys,'/','继电特性'],[50,155;50,110;65,110])
add_line([sys,'/','继电特性'],[105,110;105,140;200,140])
add_line([sys,'/','继电特性'],[165,115;165,125;200,125])
add_line([sys,'/','继电特性'],[170,55;185,55;185,95;200,95])
add_line([sys,'/','继电特性'],[315,125;325,125])
set_param([sys,'/','继电特性'],...
'Mask Display','plot(0,0,100,100,[93,6],[50,50],[50,50],[8,92],[70,70,83,60,60],[50,80,80,80,51],[29,29,14,40,40],[50,20,20,20,50])',...
'Mask Type','Relay')
set_param([sys,'/','继电特性'],...
'Mask Dialogue','Relay:\n m: relay coff;\n h :Input for relay on;\n M :Output when relay on\n|m: [ (0<m>=1) or (m=-1) ]|h: [ h>=0 ]|M: [ M>0 ]',...
'Mask Translate','m=@1;h=@2;val=@3;')
set_param([sys,'/','继电特性'],...
'Mask Entries','-1\/0.1\/1\/')
% Finished composite block '继电特性'.
set_param([sys,'/','继电特性'],...
'position',[35,240,70,280])
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 + -