fuzzy31.m

来自「FISMAT accommodates different arithmetic」· M 代码 · 共 75 行

M
75
字号
function  [sys, x0]  = fuzzy31(t,x,u,flag,ctr,ts)% [sys,x0] = fuzzy31(t,x,u,flag,ctr,ts) %% Simulink S-function-file. fuzzy31 means Fuzzy-Logic-Controller (discrete)% with three inputs and one output.% ctr=string with the controller M-filename.% ts = sample time.% eset,deset,sset are sets given to the controller.% Calling this s-function with flag=0 must return a sys-vector:% sys(1) number of continuous states       here: =0% sys(2) number of discrete states x(n+1)        =7% sys(3) number of outputs                       =1% sys(4) number of inputs                        =3% sys(5) number of discontinuous roots% sys(6) flag for direct feedthrough (used for finding algebraic loops)% Note that because the step time of the SIMULINK integrator is much smaller% than the sampling interval of the discrete block, there is an implicit % zero-order hold on the output of the unit delay.% u   = actual inputs at this sample point.% x(1)= the last first-input value - one sample period ts ago.% x(2)= the last second-input value - one sample period ts ago.% x(3)= the last third-input value - one sample period ts ago.% x(4)= the last output-value - one sample period ts ago.% x(5)= the first-input value two sample periods ago.% x(6)= the second-input value two sample periods ago.% x(7)= the third-input value two sample periods ago.% In the controller file you can decide if the controller needs one sample % period to evalute the actual output. (This is more realistic for fuzzy-% controller). That means in the controller file x(1),x(2),x(3) are used as% the input values instead of u.%% FSTB - Fuzzy Systems Toolbox for MATLAB% Copyright (c) 1993-1996 by Olaf Wolkenhauer% Control Systems Centre at UMIST% Manchester M60 1QD, UK%% 21-April-1994 % offset time (sample time is given as the parameter ts)offset = 0;if abs(flag) == 2  % Return discrete states in sys  % Is it a sample hit (within a tolerance of 1e-8) ?  if abs(round((t - offset)/ts) - (t - offset)/ts) < 1e-8    sys(1) = u(1);    sys(2) = u(2);    sys(3) = u(3);    sys(4) = feval(ctr,u,x,ts);    sys(5) = x(1);    sys(6) = x(2);    sys(7) = x(3);  else    % otherwise, just set it equal to its last value.    sys = x;  endelseif flag == 3  % Return outputs% Is it a sample hit (within a tolerance of 1e-8) ?  if abs(round((t - offset)/ts) - (t - offset)/ts) < 1e-8    sys(1) = feval(ctr,u,x,ts);  else    % otherwise, just set it equal to its last value.    sys = x(4);  endelseif flag == 4 % Return next sample hit% ns stores the number of samples  ns = (t - offset)/ts;% This is the time of the next sample hit.  sys = offset + (1 + floor(ns + 1e-13*(1+ns)))*ts;elseif flag  == 0,  % Initial conditions and size information  sys = [0;7;1;3;0;0]; % seven states, one output, three inputs.  x0  = zeros(7,1); else   sys = [];end;

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?