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

📄 fc.m

📁 基于Fuzzy 理论的 倒立摆 Matlab仿真系统 源代码
💻 M
字号:
function y=fc(e,e_dot)
%Rule Base
rule_base=[4,4,4,3,2;
           4,4,3,2,1;
           4,3,2,1,0;
           3,2,1,0,0;
           2,1,0,0,0;];
%gains
g0=1;
g1=1;
h=1;
%input of fuzzy controller ( [-pi/2,pi/2]->[-2,2]; [-pi/4,pi/4]->[-2,2])
ee=e*g0*4/pi;
ee_dot=e_dot*g1*8/pi;
% [-2,2]->[1,5]
x1=ee+3;
x2=ee_dot+3;


%Find the fuzzy sets of the inputs. i for e,  j for e_dot;

i=[floor(x1),floor(x1)+1];
j=[floor(x2),floor(x2)+1];
if i(1)>=5
    i=[5,5];
elseif i(1)<1
    i=[1,1];
end;

if j(1)>=5
    j=[5,5];
elseif j(1)<1
    j=[1,1];
end;

%snum represents the 4 combinations of the IF part(premise);
snum=[1,1;1,2;2,1;2,2];
%Initialize the num and den to zero.
num=0;den=0;
%Circulate 4 times to exhaust the Possible rules.
for k=1:4
    
% One combination of fuzzy sets. i1 for x1.  j1 for x2.
    i1=i(snum(k,1));
    j1=j(snum(k,2));
    
% The membership values of inputs on the outermost.
    if x1>5 || x1<1
        mf1(k)=1;
    else
        mf1(k)=1-abs(x1-i1);
    end;
    if x2>5 || x2<1
        mf2(k)=1;
    else
        mf2(k)=1-abs(x2-j1);
    end;
    
% Inference Engine
    prem(k)=min(mf1(k),mf2(k));
% The COG defuzzification; (h is the gain)
    imps(k)=2*(prem(k)-prem(k)^2/2);
    center(k)=(rule_base(i1,j1)-2)*10*h;    
    num=num+imps(k)*center(k);
    den=den+imps(k);
end;
%Output of the Fuzzy Control
y=num/den;
%y have peaks at +-20 N.
if y>20 
    y=20;
end;
if y<-20
    y=-20;
end;

⌨️ 快捷键说明

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