Fuzzy control designer
Definition
The form of fuzzy rules is: if x is A then y is B. Where A and B are linguistic values defined by fuzzy sets on the universe X and Y. "X is A" is called premise, and "y is B" is called conclusion.
The above fuzzy rules can be abbreviated as A → B. Essentially the fuzzy rule is a binary fuzzy relationship R defined on X × Y. There are two explanations for A → B, one is A coupled with B, and the other is entails B. Based on these two interpretations and different tnorm and tconorm operators, fuzzy rules can have a variety of legal calculation formulas.
Code
% Fuzzy controller design
a = newfis ('fuzzf');% Create a new fuzzy inference system
% Input 1
f1 = 1;
a = addvar (a, 'input', 'e', [-3 f1,3 f1]);
% fuzzy language variable of adding e
a = addmf (a, 'input', 1, 'NB', 'zmf', [-3 f1, -1 f1]);
% membership function (z type) of fuzzy linguistic variables with e added
a = addmf (a, 'input', 1, 'NM', 'trimf', [-3 f1, -2 f1,0]);
% membership function is triangle
a = addmf (a, 'input', 1, 'NS', 'trimf', [-3 f1, -1 f1,1 f1]);
a = addmf (a, 'input', 1, 'Z', 'trimf', [-2 f1,0,2 f1]);
a = addmf (a, 'input', 1 , 'PS', 'trimf', [-1 f1,1 f1,3 f1]);
a = addmf (a, 'input', 1, 'PM', 'trimf', [0,2 f1,3 f1 ]);
a = addmf (a, 'input', 1, 'PB', 'smf', [1 f1,3 f1]);
%输出
f3=1.5;
a=addvar(a,‘output’,‘u’,[-3f3,3f3]);
%添加 u 的模糊语言变量
a=addmf(a,‘output’,1,‘NB’,‘zmf’,[-3f3,-1f3]);
a=addmf(a,‘output’,1,‘NM’,‘trimf’,[-3f3,-2f3,0]);
a=addmf(a,‘output’,1,‘NS’,‘trimf’,[-3f3,-1f3,1f3]);
a=addmf(a,‘output’,1,‘Z’,‘trimf’,[-2f3,0,2f3]);
a=addmf(a,‘output’,1,‘PS’,‘trimf’,[-1f3,1f3,3f3]);
a=addmf(a,‘output’,1,‘PM’,‘trimf’,[0,2f3,3f3]);
a=addmf(a,‘output’,1,‘PB’,‘smf’,[1f3,3f3]);
% Rule base
rulelist = [1 1 1 1 1;% edit fuzzy rules, the last two numbers are rule weights and AND OR options
1 2 1 1 1;
1 3 1 1 1;
1 4 2 1 1;
1 5 2 1 1;
1 6 3 1 1;
1 7 4 1 1;
2 1 1 1 1;
2 2 2 1 1;
2 3 2 1 1;
2 4 2 1 1;
2 5 3 1 1;
2 6 4 1 1;
2 7 5 1 1;
Use the fuzzy logic toolbox function provided by MATLAB to
create a new fuzzy inference system (fuzzy controller). The
input and output quantization levels are 7 levels
e, ec, u = (-3, -2, -1,0, 1, 2, 3} Take 7 linguistic values each, which can be taken as: fuzzy subsets: small, zero, positive small, median, positive e, ec's universe = [-3, 3] u's universe = [-4. 5 , 4. 5] The membership function is arbitrarily determined.
operation result
New rules added:
3 1 1 1 1
3 2 2 1 1
3 3 3 1 1
3 4 3 1 1
3 5 4 1 1
3 6 5 1 1
3 7 6 1 1
4 1 1 1 1
4 2 3 1 1
4 3 3 1 1
4 4 3 1 1
4 5 4 1 1
4 6 5 1 1
4 7 6 1 1];