tp2dem_s.m
来自「FISMAT accommodates different arithmetic」· M 代码 · 共 301 行
M
301 行
function [ret,x0,str]=tp2dem_s(t,x,u,flag);%TP2DEM_S is the M-file description of the SIMULINK system named TP2DEM_S.% The block-diagram can be displayed by typing: TP2DEM_S.%% SYS=TP2DEM_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 TP2DEM_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 TP2DEM_S with a FLAG of zero:% [SIZES]=TP2DEM_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 - table look - up. Fuzzy-Toolbox O.Wolkenhauer 22-April 1994',13,'Execute script tp2_dat.m from workspace to specify controller and simulation parameters.']])set_param([sys,'/',['Closed Loop System with a nonlinear discrete fuzzy controller - table look - up. Fuzzy-Toolbox O.Wolkenhauer 22-April 1994',13,'Execute script tp2_dat.m from workspace to specify controller and simulation parameters.']],... 'position',[286,375,287,376])add_block('built-in/Note',[sys,'/','*) Subsystem function name: X-index: rate Y-index: error Table: tp_look'])set_param([sys,'/','*) Subsystem function name: X-index: rate Y-index: error Table: tp_look'],... '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])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/Note',[sys,'/','Fuzzy-Controller'])set_param([sys,'/','Fuzzy-Controller'],... 'position',[336,15,337,16])% Subsystem '2-D Table Lookup'.new_system([sys,'/','2-D Table Lookup'])set_param([sys,'/','2-D Table Lookup'],'Location',[316,263,598,417])add_block('built-in/Inport',[sys,'/','2-D Table Lookup/y0'])set_param([sys,'/','2-D Table Lookup/y0'],... 'Port','2',... 'position',[20,80,40,100])add_block('built-in/Outport',[sys,'/','2-D Table Lookup/table out'])set_param([sys,'/','2-D Table Lookup/table out'],... 'position',[215,55,235,75])add_block('built-in/Inport',[sys,'/','2-D Table Lookup/x0'])set_param([sys,'/','2-D Table Lookup/x0'],... 'position',[20,25,40,45])add_block('built-in/S-function',[sys,'/','2-D Table Lookup/S-function'])set_param([sys,'/','2-D Table Lookup/S-function'],... 'function name','sftable2',... 'parameters','xindex, yindex, table',... 'position',[140,52,190,78])add_block('built-in/Mux',[sys,'/','2-D Table Lookup/Mux'])set_param([sys,'/','2-D Table Lookup/Mux'],... 'inputs','2',... 'position',[90,46,120,79])add_line([sys,'/','2-D Table Lookup'],[45,90;65,90;65,70;80,70])add_line([sys,'/','2-D Table Lookup'],[195,65;205,65])add_line([sys,'/','2-D Table Lookup'],[45,35;65,35;65,55;80,55])add_line([sys,'/','2-D Table Lookup'],[125,65;130,65])set_param([sys,'/','2-D Table Lookup'],... 'Mask Display','plot(-10,-10,110,110,[90,50,10],[90,40,30],[90,50,10],[50,26,20],[90,50,10],[22,13,10])',... 'Mask Type','2-D Table Lookup')set_param([sys,'/','2-D Table Lookup'],... 'Mask Dialogue','Two Dimensional Table Lookup\nThe first input corresponds to X Index and the second input corresponds to the Y Index|X Index|Y Index|Table')set_param([sys,'/','2-D Table Lookup'],... 'Mask Translate','xindex=@1; yindex=@2; table=@3; sftab2chk(xindex,yindex,table);')set_param([sys,'/','2-D Table Lookup'],... 'Mask Help','This block returns a linearly interpolated intersection from the table using the X index (which corresponds to the rows of the table) and the Y index (which corresponds to the columns of the table). Extrapolation is used.')set_param([sys,'/','2-D Table Lookup'],... 'Mask Entries','rate\/error\/tp_look\/')% Finished composite block '2-D Table Lookup'.set_param([sys,'/','2-D Table Lookup'],... 'position',[280,39,325,81])add_block('built-in/Gain',[sys,'/','Ke'])set_param([sys,'/','Ke'],... 'position',[200,80,220,100])add_block('built-in/Unit Delay',[sys,'/','Unit Delay'])set_param([sys,'/','Unit Delay'],... 'Sample time','0.1',... 'position',[110,12,160,28])add_block('built-in/Sum',[sys,'/','Sum1'])set_param([sys,'/','Sum1'],... 'inputs','-+',... 'position',[190,14,215,41])add_block('built-in/Gain',[sys,'/','Kde'])set_param([sys,'/','Kde'],... 'position',[230,20,250,40])add_block('built-in/Note',[sys,'/','Plant'])set_param([sys,'/','Plant'],... 'position',[560,15,561,16])add_block('built-in/Transfer Fcn',[sys,'/','Transfer Fcn'])set_param([sys,'/','Transfer Fcn'],... 'Numerator','[5]',... 'Denominator','[20 1]',... 'position',[530,38,590,82])add_block('built-in/To Workspace',[sys,'/','To Workspace1'])set_param([sys,'/','To Workspace1'],... 'mat-name','yout',... 'position',[625,157,675,173])% 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',[635,41,665,79])% 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',[475,42,505,78])add_block('built-in/Gain',[sys,'/','Kdy'])set_param([sys,'/','Kdy'],... 'position',[430,50,450,70])add_block('built-in/Discrete Transfer Fcn',[sys,'/','Zero Order Hold'])set_param([sys,'/','Zero Order Hold'],... 'Numerator','1',... 'Denominator','1',... 'Sample time','Ts',... 'Mask Display','plot(0,0,100,100,[90,70,70,50,50,30,30,10],[30,30,50,50,80,80,20,20])',... 'Mask Type','Zero Order Hold')set_param([sys,'/','Zero Order Hold'],... 'Mask Dialogue','Zero Order Hold|Sample Time:',... 'Mask Translate','Ts=@1;',... 'Mask Help','Implements a sample-and-hold latch operating at the sampling interval you specify.')set_param([sys,'/','Zero Order Hold'],... 'Mask Entries','.3\/',... 'position',[365,44,395,76])add_block('built-in/Note',[sys,'/','*)'])set_param([sys,'/','*)'],... 'position',[305,95,306,96])add_line(sys,[60,250;125,250])add_line(sys,[35,30;50,30])add_line(sys,[595,60;625,60])add_line(sys,[595,60;595,165;615,165])add_line(sys,[595,165;45,165;45,45;50,45])add_line(sys,[90,40;90,90;190,90])add_line(sys,[220,30;220,30])add_line(sys,[455,60;465,60])add_line(sys,[510,60;520,60])add_line(sys,[255,30;270,50])add_line(sys,[225,90;270,70])add_line(sys,[90,40;90,20;100,20])add_line(sys,[165,20;180,20])add_line(sys,[160,90;160,35;180,35])add_line(sys,[400,60;420,60])add_line(sys,[330,60;355,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 + -
显示快捷键?