📄 pops.m
字号:
function [ret,x0,str,ts,xts]=pops(t,x,u,flag);
%POPS is the M-file description of the SIMULINK system named POPS.
% The block-diagram can be displayed by typing: POPS.
%
% SYS=POPS(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 POPS 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 POPS with a FLAG of zero:
% [SIZES]=POPS([],[],[],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',[7,56,435,335])
open_system(sys)
end;
set_param(sys,'algorithm', 'RK-45')
set_param(sys,'Start time', '0.0')
set_param(sys,'Stop time', '299')
set_param(sys,'Min step size', '0.0001')
set_param(sys,'Max step size', '1')
set_param(sys,'Relative error','1e-3')
set_param(sys,'Return vars', '')
set_param(sys,'Load callback','initial_pop=20;');
add_block('built-in/Sum',[sys,'/','Sum'])
set_param([sys,'/','Sum'],...
'hide name',0,...
'inputs','+-',...
'position',[165,85,185,120])
add_block('built-in/Integrator',[sys,'/','pop'])
set_param([sys,'/','pop'],...
'Initial','initial_pop',...
'position',[210,88,245,122])
add_block('built-in/Fcn',[sys,'/','u*u'])
set_param([sys,'/','u*u'],...
'Expr','u*u',...
'position',[295,87,330,123])
add_block('built-in/Gain',[sys,'/','b'])
set_param([sys,'/','b'],...
'Gain','0.0005157',...
'position',[75,120,115,160])
add_block('built-in/Gain',[sys,'/','a'])
set_param([sys,'/','a'],...
'Gain','0.02309',...
'position',[75,40,110,80])
% Subsystem 'More Info'.
new_system([sys,'/','More Info'])
set_param([sys,'/','More Info'],'Location',[0,56,378,234])
add_block('built-in/Note',[sys,'/',['More Info/To see a longer demo, just type "popdemo" at the command ',13,'line while the "pops" window is open.']])
set_param([sys,'/',['More Info/To see a longer demo, just type "popdemo" at the command ',13,'line while the "pops" window is open.']],...
'position',[181,115,186,120])
add_block('built-in/Note',[sys,'/',['More Info/Change the parameter initial_pop in the workspace and',13,'see how the final population outcome is affected.']])
set_param([sys,'/',['More Info/Change the parameter initial_pop in the workspace and',13,'see how the final population outcome is affected.']],...
'position',[173,65,178,70])
add_block('built-in/Note',[sys,'/',['More Info/This system models a population in which the number',13,'of members follows the law dm//dt = a*m - b*m*m.']])
set_param([sys,'/',['More Info/This system models a population in which the number',13,'of members follows the law dm//dt = a*m - b*m*m.']],...
'position',[167,15,172,20])
set_param([sys,'/','More Info'],...
'Mask Display','?')
% Finished composite block 'More Info'.
set_param([sys,'/','More Info'],...
'hide name',0,...
'Drop Shadow',4,...
'position',[315,195,342,220])
add_block('built-in/Note',[sys,'/',['Population Variation',13,'(Double click on the "?" for more info)']])
set_param([sys,'/',['Population Variation',13,'(Double click on the "?" for more info)']],...
'position',[175,195,180,200])
add_block('built-in/Note',[sys,'/',['To run the simulation, select "Start"',13,'from the "Simulation" pull-down menu']])
set_param([sys,'/',['To run the simulation, select "Start"',13,'from the "Simulation" pull-down menu']],...
'position',[175,235,180,240])
add_block('built-in/Scope',[sys,'/','Scope'])
set_param([sys,'/','Scope'],...
'Vgain','100.000000',...
'Hgain','300.000000',...
'Vmax','200.000000',...
'Hmax','600.000000',...
'Window',[392,170,654,367])
open_system([sys,'/','Scope'])
set_param([sys,'/','Scope'],...
'position',[325,6,350,34])
add_line(sys,[335,105;350,105;350,180;40,180;40,140;70,140])
add_line(sys,[115,60;140,60;140,95;160,95])
add_line(sys,[190,105;205,105])
add_line(sys,[120,140;140,140;140,110;160,110])
add_line(sys,[250,105;290,105])
add_line(sys,[270,105;270,20;40,20;40,60;70,60])
add_line(sys,[270,20;320,20])
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 + -