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

📄 fastfuzzy.m

📁 这是一个基于模糊控制的温度控制的系统matlab仿真程序
💻 M
字号:
% THIS M-FILE IS CREATED BY A.RAMEZANIFAR,student of TEHRAN POLITECHNINC UNIVERSITY
% ELECTRICLA ENGINEERING DEPARTMENT, 
% 
%
% This program is useful for fast implementation of a fuzzy logic controller. Suppose a fuzzy controller
% with two inputs and 1 output. From various choices to implement it, if we choose product inference 
% engine, singleton fuzzifier and center average defuzzifier (which is very commonplace choice)
% the output will be as :
% 
%    __    _l    _l    _l
%    \     y ( m_A . m_B )
%    /__
%     l
% y= -------------------
%    __       _l    _l
%    \    ( m_A . m_B )
%    /__
%     l
%        _l
% where  y  denotes center of  l-th rule and  M_A and M_B are input membership functions of first input (A)
% and second input (B) respectively. To calculate y, the software needs to use two intricate loops and this 
% waste enormous amount of time which decreases simulation speed. 
% In the following we calculate y with using matrix algebra which prompts simulation time. this formula is 
% beneficent for use both in m-file and SIMULINK. In the following there is a function which receives 
% two values as inputs and returns the output based on fuzzy rules. If one wants to use it in a SIMULINK, 
% it can be written in embeddable  MATLAB function block .
 
function y = fcn(u)
 
x1=u(1);   %the first input value
x2=u(2);   %the second input value
% For each of two inputs n & m fuzzy membership functions are constructed respectively. n*m  fuzzy rules
% are constructed to obtain the fuzzy output.
% Going on three steps we produce three matrices and refer to them before long. 
% The A  matrix is composed of n  evaluated membership functions of the first input  
% ---------------------------
% A=[M_A_1  M_A_2 ... M_A_n];
% evaluate member ship functions of the first input : ( in the following example there are three 
% membership functions for each inputs )
SIGMA=2.14;
C=-8;
N_A=exp(-(x1 - C).^2/(2*SIGMA^2));
 
SIGMA=2.5;
C=-5.5;
ZR_A_left=1./(1 + exp(-A*(x1-C)));
 
SIGMA=2.5;
C=5.5;
ZR_A_right=1./(1 + exp(-A*(x1-C)));
 
ZR_A=ZR_P_right-ZR_P_left;
 
SIGMA=2.14;
C=8;
P_A=exp(-(x1 - C).^2/(2*SIGMA^2));
 
A=[N_A ZR_A P_A];
% Similarly the B matrix is composed with evaluating m membership functions of second input.
% B=[M_B_1  M_B_2 ... M_B_m];
%---------------------------
%evaluate membership functions of the second input
SIGMA=0.009;
C=-0.025;
N_B=exp(-(x2 - C).^2/(2*SIGMA^2));
 
SIGMA=500;
C=-0.014;
ZR_B_left=1./(1 + exp(-A*(x2-C)));
 
SIGMA=500;
C=0.014;
ZR_B_right=1./(1 + exp(-A*(x2-C)));
 
ZR_B=ZR_Pd_right-ZR_Pd_left;
 
SIGMA=0.009;
C=0.025;
P_B=exp(-(x2 - C).^2/(2*SIGMA^2));
 
B=[N_B ZR_B P_B];
%-------------------------------------------------------
% The fuzzy rules are given in table below:
% 
%                               first input
% 
%                        |M_A_1     M_A_2 ... M_A_n
%                   ------------------------------
%                   M_B_1|M_y_1     M_y_2 ...  M_Y_m
%                        |         
%                   M_B_2|M_y_(n+1)   ...          
%    second input     .  |  
%                     .  | ... 
%                     .  |
%                   M_B_m|...                  M_y_(n*m)
%                   -----|---------------------------
%                                   output
%                                       
% 
% the fist row describes the first input and the first column describes the second input. The fuzzy value for
% the output is obtained by reading the cell representing the intersection of the applicable column and row. 
%            
% With regard to the this table the matrix R is made in such a way that each elements of it 
% conforms to the center of membership function in the same element in the table above.
 
% the center of membership functions of the output (in this example output has three membership function) :
N_y=-5;
ZR_y=0;
P_y=5;
%there are 3*3=9 rules
R=[P_y   P_y   P_y;
   P_y   ZR_y  N_y ;
   ZR_y  N_y   N_y]; 

 
% in this condition, with using some operations and arrangments, the output y reforms in the form of :
% y= ( A'*R*B )/( sum(A).sum(B) ) 
% sum denotes summation on the vector's  elements 
 
a=A'*Press_sp*B;
b=sum(A)*sum(B);
y=a/b;
 
% therefore we can calculate the output using matrix algebra which is more faster than using 
% fuzzy logic controller block in the SIMULINK. In comparison with Fuzzy toolbox, in complicated systems,
% the speed of simulation is improved.
  
      



⌨️ 快捷键说明

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