tp_dem_s.m
来自「FISMAT accommodates different arithmetic」· M 代码 · 共 246 行
M
246 行
function [ret,x0,str]=tp_dem_s(t,x,u,flag);%TP_DEM_S is the M-file description of the SIMULINK system named TP_DEM_S.% The block-diagram can be displayed by typing: TP_DEM_S.%% SYS=TP_DEM_S(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 TP_DEM_S 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 TP_DEM_S with a FLAG of zero:% [SIZES]=TP_DEM_S([],[],[],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.% 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.2)if(0 == (nargin + nargout)) set_param(sys,'Location',[4,42,628,468]) open_system(sys)end;set_param(sys,'algorithm', 'RK-23')set_param(sys,'Start time', '0.0')set_param(sys,'Stop time', '20')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/Note',[sys,'/',['Closed Loop System with a nonlinear discrete fuzzy controller. Fuzzy-Toolbox O.Wolkenhauer 22-April 1994',13,'Execute script tp_dat.m from workspace before simulation to specify controller and simulation parameters.']])set_param([sys,'/',['Closed Loop System with a nonlinear discrete fuzzy controller. Fuzzy-Toolbox O.Wolkenhauer 22-April 1994',13,'Execute script tp_dat.m from workspace before simulation to specify controller and simulation parameters.']],... 'position',[286,375,287,376])add_block('built-in/Note',[sys,'/',['*) Subsystem function name: FUZZY21 und Function parameters: ''tp_dem_c'',Ts=0.1']])set_param([sys,'/',['*) Subsystem function name: FUZZY21 und Function parameters: ''tp_dem_c'',Ts=0.1']],... 'position',[257,315,258,316])add_block('built-in/To Workspace',[sys,'/','To Workspace'])set_param([sys,'/','To Workspace'],... 'mat-name','t',... 'position',[135,242,185,258])add_block('built-in/Clock',[sys,'/','Clock'])set_param([sys,'/','Clock'],... 'position',[35,240,55,260])% Subsystem 'Graph Scope'.new_system([sys,'/','Graph Scope'])set_param([sys,'/','Graph Scope'],'Location',[0,0,274,193])add_block('built-in/S-function',[sys,'/',['Graph Scope/S-function',13,'M-file which plots',13,'lines',13,'']])set_param([sys,'/',['Graph Scope/S-function',13,'M-file which plots',13,'lines',13,'']],... 'function name','sfuny',... 'parameters','ax, color',... 'position',[130,55,180,75])add_block('built-in/Inport',[sys,'/','Graph Scope/x'])set_param([sys,'/','Graph Scope/x'],... 'position',[65,55,85,75])add_line([sys,'/','Graph Scope'],[90,65;120,65])set_param([sys,'/','Graph Scope'],... 'Mask Display','plot(0,0,100,100,[90,10,10,10,90,90,10],[65,65,90,40,40,90,90],[90,78,69,54,40,31,25,10],[77,60,48,46,56,75,81,84])',... 'Mask Type','Graph scope.')set_param([sys,'/','Graph Scope'],... 'Mask Dialogue','Graph scope using MATLAB graph window.\nEnter plotting ranges and line type.|Time range:|y-min:|y-max:|Line type (rgbw-:*)::',... 'Mask Translate','color = @4; ax = [0, @1, @2, @3];')set_param([sys,'/','Graph Scope'],... 'Mask Help','This block plots to the MATLAB graph window and can be used as an improved version of the Scope block. Look at the m-file sfuny.m to see how it works.',... 'Mask Entries','20\/0\/10\/''g''\/')% Finished composite block 'Graph Scope'.set_param([sys,'/','Graph Scope'],... 'Drop Shadow',4,... 'position',[570,41,600,79])add_block('built-in/To Workspace',[sys,'/','To Workspace1'])set_param([sys,'/','To Workspace1'],... 'mat-name','yout',... 'position',[560,157,610,173])add_block('built-in/S-function',[sys,'/','S-function'])set_param([sys,'/','S-function'],... 'function name','fuzzy21',... 'parameters','''tp_dem_c'',0.1',... 'position',[300,40,360,80])add_block('built-in/Mux',[sys,'/','Mux'])set_param([sys,'/','Mux'],... 'inputs','2',... 'position',[255,40,285,75])add_block('built-in/Sum',[sys,'/','Sum'])set_param([sys,'/','Sum'],... 'inputs','-+',... 'position',[60,24,85,51])add_block('built-in/Step Fcn',[sys,'/','Step Fcn'])set_param([sys,'/','Step Fcn'],... 'Time','0',... 'After','6',... 'position',[10,20,30,40])add_block('built-in/Gain',[sys,'/','Ke'])set_param([sys,'/','Ke'],... 'position',[195,30,215,50])add_block('built-in/Transfer Fcn',[sys,'/','Transfer Fcn'])set_param([sys,'/','Transfer Fcn'],... 'Numerator','[5]',... 'Denominator','[20 1]',... 'position',[465,38,525,82])add_block('built-in/Note',[sys,'/','Plant'])set_param([sys,'/','Plant'],... 'position',[495,15,496,16])add_block('built-in/Unit Delay',[sys,'/','Unit Delay'])set_param([sys,'/','Unit Delay'],... 'Sample time','0.1',... 'position',[110,117,160,133])add_block('built-in/Sum',[sys,'/','Sum1'])set_param([sys,'/','Sum1'],... 'inputs','+-',... 'position',[180,104,205,131])add_block('built-in/Gain',[sys,'/','Kde'])set_param([sys,'/','Kde'],... 'position',[220,110,240,130])add_block('built-in/Note',[sys,'/','Fuzzy-Controller'])set_param([sys,'/','Fuzzy-Controller'],... 'position',[336,15,337,16])% Subsystem 'Lim. Integrator'.new_system([sys,'/','Lim. Integrator'])set_param([sys,'/','Lim. Integrator'],'Location',[0,0,791,233])add_block('built-in/Saturation',[sys,'/','Lim. Integrator/Saturation'])set_param([sys,'/','Lim. Integrator/Saturation'],... 'Lower Limit','lb',... 'Upper Limit','ub',... 'position',[630,121,675,149])add_block('built-in/Fcn',[sys,'/','Lim. Integrator/Fcn'])set_param([sys,'/','Lim. Integrator/Fcn'],... 'Expr','u[2]*((((u[1]>lb)+(u[2]>=0))>0) * (((u[1]<ub)+(u[2]<=0))>0))',... 'position',[150,116,520,154])add_block('built-in/Inport',[sys,'/','Lim. Integrator/In_1'])set_param([sys,'/','Lim. Integrator/In_1'],... 'position',[20,130,40,150])add_block('built-in/Outport',[sys,'/','Lim. Integrator/Out_1'])set_param([sys,'/','Lim. Integrator/Out_1'],... 'position',[720,125,740,145])add_block('built-in/Integrator',[sys,'/','Lim. Integrator/Integrator'])set_param([sys,'/','Lim. Integrator/Integrator'],... 'Initial','xi',... 'position',[540,126,585,144])add_block('built-in/Mux',[sys,'/','Lim. Integrator/Mux'])set_param([sys,'/','Lim. Integrator/Mux'],... 'inputs','2',... 'position',[85,116,115,149])add_line([sys,'/','Lim. Integrator'],[680,135;710,135])add_line([sys,'/','Lim. Integrator'],[45,140;75,140])add_line([sys,'/','Lim. Integrator'],[120,135;140,135])add_line([sys,'/','Lim. Integrator'],[525,135;530,135])add_line([sys,'/','Lim. Integrator'],[590,135;620,135])add_line([sys,'/','Lim. Integrator'],[600,135;600,35;55,35;55,125;75,125])set_param([sys,'/','Lim. Integrator'],... 'Mask Display','plot(-1,-0.2,3.5,1.2,[0.05,1,2,2.9],[0,0,1,1]); 1/s ',... 'Mask Type','Limited integrator.',... 'Mask Dialogue','Limited integrator|Lower bound:|Upper bound:|Initial condition')set_param([sys,'/','Lim. Integrator'],... 'Mask Translate','lb = @1; ub = @2; xi = @3;',... 'Mask Help','Implements a limited integrator with \nan expression of the form:\n\nif(x<=lb and u<0) or (x>=ub and u>0)\n\txdot=0\nelse\n\txdot=u.')set_param([sys,'/','Lim. Integrator'],... 'Mask Entries','-10\/10\/0\/')% Finished composite block 'Lim. Integrator'.set_param([sys,'/','Lim. Integrator'],... 'position',[415,42,445,78])add_block('built-in/Gain',[sys,'/','Kdy'])set_param([sys,'/','Kdy'],... 'position',[375,50,395,70])add_block('built-in/Note',[sys,'/','*)'])set_param([sys,'/','*)'],... 'position',[325,95,326,96])add_line(sys,[60,250;125,250])add_line(sys,[35,30;50,30])add_line(sys,[290,60;290,60])add_line(sys,[530,60;560,60])add_line(sys,[530,60;530,165;550,165])add_line(sys,[530,165;45,165;45,45;50,45])add_line(sys,[220,40;245,50])add_line(sys,[245,120;245,65])add_line(sys,[90,40;185,40])add_line(sys,[100,40;100,125])add_line(sys,[165,125;170,125])add_line(sys,[160,40;160,110;170,110])add_line(sys,[210,120;210,120])add_line(sys,[365,60;365,60])add_line(sys,[400,60;405,60])add_line(sys,[450,60;455,60])% 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]=',sys,'(t,x,u,flag);']) else eval(['ret =', sys,'(t,x,u,flag);']) end else [ret,x0,str] = feval(sys); endend
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?