⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fuzzy21.m

📁 FISMAT accommodates different arithmetic operators, fuzzification and defuzzification algorithm, imp
💻 M
字号:
function  [sys, x0]  = fuzzy21(t,x,u,flag,ctr,ts)% [sys,x0] = fuzzy21(t,x,u,flag,ctr,ts) %% Simulink S-function-file. Fuzzy21 means Fuzzy-Controller (discrete)% with two inputs and one output.% ctr=string with the controller M-filename.% ts = sample time.% 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)        =5% sys(3) number of outputs                       =1% sys(4) number of inputs                        =2% 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 output-value - one sample period ts ago.% x(4)= the first-input value two sample periods ago.% x(5)= the second-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) are used as the input% value 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%% 19-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) = feval(ctr,u,x,ts);    sys(4) = x(1);    sys(5) = x(2);  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(3);  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;5;1;2;0;0]; % five states, one output, two inputs.  x0  = zeros(5,1); else   sys = [];end;

⌨️ 快捷键说明

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