📄 spm2.m
字号:
function [ret,x0,str,ts,xts]=spm2(t,x,u,flag);
%SPM2 is the M-file description of the SIMULINK system named SPM2.
% The block-diagram can be displayed by typing: SPM2.
%
% SYS=SPM2(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 SPM2 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 SPM2 with a FLAG of zero:
% [SIZES]=SPM2([],[],[],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',[784,63,1236,242])
open_system(sys)
end;
set_param(sys,'BackGround',5)
set_param(sys,'algorithm', 'RK-45')
set_param(sys,'Start time', '0.0')
set_param(sys,'Stop time', '999999')
set_param(sys,'Min step size', '0.0001')
set_param(sys,'Max step size', '10')
set_param(sys,'Relative error','1e-3')
set_param(sys,'Return vars', '')
add_block('built-in/Note',[sys,'/','Spring-mass-damper with a stiffening spring'])
set_param([sys,'/','Spring-mass-damper with a stiffening spring'],...
'position',[215,31,220,39])
% Subsystem 'DEE'.
new_system([sys,'/','DEE'])
set_param([sys,'/','DEE'],'Location',[100,100,600,400])
add_block('built-in/Mux',[sys,'/','DEE/SysMux'])
set_param([sys,'/','DEE/SysMux'],...
'inputs','3',...
'position',[100,199,150,251])
add_block('built-in/Fcn',[sys,'/','DEE/x1'])
set_param([sys,'/','DEE/x1'],...
'Expr','u(3) ',...
'position',[300,50,330,70])
add_block('built-in/Integrator',[sys,'/','DEE/Integ1'])
set_param([sys,'/','DEE/Integ1'],...
'position',[400,50,430,70])
add_block('built-in/Fcn',[sys,'/','DEE/x2'])
set_param([sys,'/','DEE/x2'],...
'Expr','-u(3)-u(2)-u(2)*u(2)*u(2)+u(1)',...
'position',[300,100,330,120])
add_block('built-in/Integrator',[sys,'/','DEE/Integ2'])
set_param([sys,'/','DEE/Integ2'],...
'position',[400,100,430,120])
add_block('built-in/Fcn',[sys,'/','DEE/y1'])
set_param([sys,'/','DEE/y1'],...
'Expr','u(2)',...
'position',[300,250,330,270])
add_block('built-in/Outport',[sys,'/','DEE/Port1'])
set_param([sys,'/','DEE/Port1'],...
'position',[400,250,420,270])
add_block('built-in/Inport',[sys,'/','DEE/SysInport1'])
set_param([sys,'/','DEE/SysInport1'],...
'position',[20,50,40,70])
add_line([sys,'/','DEE'],[45,60;65,60;65,210;95,210])
add_line([sys,'/','DEE'],[155,225;220,225;220,60;295,60])
add_line([sys,'/','DEE'],[335,60;395,60])
add_line([sys,'/','DEE'],[435,60;445,60;445,140;75,140;75,225;95,225])
add_line([sys,'/','DEE'],[155,225;220,225;220,110;295,110])
add_line([sys,'/','DEE'],[335,110;395,110])
add_line([sys,'/','DEE'],[435,110;445,110;445,145;70,145;70,240;95,240])
add_line([sys,'/','DEE'],[155,225;220,225;220,260;295,260])
add_line([sys,'/','DEE'],[335,260;395,260])
set_param([sys,'/','DEE'],...
'Mask Display','Spring-mass-damper\nsystem',...
'Mask Type','Differential Equation Editor (DEE)',...
'Mask Dialogue','eval(''diffeqed'')')
% Finished composite block 'DEE'.
set_param([sys,'/','DEE'],...
'BackGround',3,...
'Drop Shadow',4,...
'position',[130,79,295,111])
add_block('built-in/Inport',[sys,'/','Inport'])
set_param([sys,'/','Inport'],...
'BackGround',4,...
'position',[45,85,65,105])
add_block('built-in/Outport',[sys,'/','Outport'])
set_param([sys,'/','Outport'],...
'BackGround',4,...
'position',[360,85,380,105])
add_line(sys,[300,95;355,95])
add_line(sys,[70,95;125,95])
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 + -