模糊系统
模糊系统的介绍
模糊控制(模糊逻辑控制),是 以模糊集合论,模糊语言变量和模糊逻辑推理的的一种具有反馈通道闭环结构的计算机控制技术
特点:1、不依赖被控对象的数学模型,只需要专家的经验、知识
2、鲁棒性和自适应性好,可对复杂系统进行有效控制(可适用于模型参数不确定或波动较大的线性和非线性系统的控制)
系统的概述
输入1,输入2的范围都是[-3,3] NB,NM,NS,Z,PS,PM,PB
输出的范围为[-4,4] NB,NM,NS,Z,PS,PM,PB
两个输入形成一个输出。用centroid作为街模糊函数方法,并将整个整个模糊系统保存在a1中,用a2把模糊函数系统从磁盘中读取出来。
%模糊控制器设计
a=newfis('fuzzf'); %创建新的模糊推理系统
%输入1
f1=1;
a=addvar(a,'input','e',[-3*f1,3*f1]);
%添加 e 的模糊语言变量
a=addmf(a,'input',1,'NB','zmf',[-3*f1,-1*f1]);
%添加 e 的模糊语言变量的隶属度函数(z型)
a=addmf(a,'input',1,'NM','trimf',[-3*f1,-2*f1,1*f1]);
%隶属度函数为三角形
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','trimf',[1*f1,3*f1,3*f1]);
%输入2
f2=1;
a=addvar(a,'input','ec',[-3*f2,3*f2]);
%添加 ec 的模糊语言变量
a=addmf(a,'input',2,'NB','zmf',[-3*f2,-1*f2]);
a=addmf(a,'input',2,'NM','trimf',[-3*f2,-2*f2,1*f2]);
a=addmf(a,'input',2,'NS','trimf',[-3*f2,-1*f2,1*f2]);
a=addmf(a,'input',2,'Z','trimf',[-2*f2,0,2*f2]);
a=addmf(a,'input',2,'PS','trimf',[-1*f2,1*f2,3*f2]);
a=addmf(a,'input',2,'PM','trimf',[0,2*f2,3*f2]);
a=addmf(a,'input',2,'PB','trimf',[1*f2,3*f2,3*f2]);
%输出
f3=1.5;
a=addvar(a,'output','u',[-3*f3,3*f3]);
%添加 u 的模糊语言变量
a=addmf(a,'output',1,'NB','zmf',[-3*f3,-1*f3]);
a=addmf(a,'output',1,'NM','trimf',[-3*f3,-2*f3,1*f3]);
a=addmf(a,'output',1,'NS','trimf',[-3*f3,-1*f3,1*f3]);
a=addmf(a,'output',1,'Z','trimf',[-2*f3,0,2*f3]);
a=addmf(a,'output',1,'PS','trimf',[-1*f3,1*f3,3*f3]);
a=addmf(a,'output',1,'PM','trimf',[0,2*f3,3*f3]);
a=addmf(a,'output',1,'PB','trimf',[1*f3,3*f3,3*f3]);
%规则库
rulelist=[1 1 1 1 1; %编辑模糊规则,后俩个数分别是规则权重和AND OR选项
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;
3 1 1 1 1;
3 2 2 1 1;
3 3 3 1 1;
3 4 4 1 1;
3 5 5 1 1;
3 6 6 1 1;
3 7 7 1 1;
4 1 4 1 1;
4 2 4 1 1;
4 3 4 1 1;
4 4 4 1 1;
4 5 4 1 1;
4 6 4 1 1;
4 7 4 1 1;
5 1 7 1 1;
5 2 6 1 1;
5 3 5 1 1;
5 4 4 1 1;
5 5 3 1 1;
5 6 2 1 1;
5 7 1 1 1;
6 1 6 1 1;
6 2 6 1 1;
6 3 6 1 1;
6 4 6 1 1;
6 5 6 1 1;
6 6 6 1 1;
6 7 6 1 1;
7 1 7 1 1;
7 2 7 1 1;
7 3 7 1 1;
7 4 7 1 1;
7 5 7 1 1;
7 6 7 1 1;
7 7 7 1 1;];
a=addrule(a,rulelist); %添加模糊规则函数
showrule(a) %显示模糊规则函数
a1=setfis(a,'DefuzzMethod','centroid'); %设置解模糊方法
writefis(a1,'fuzzf'); %保存模糊系统
a2=readfis('fuzzf'); %从磁盘读出保存的模糊系统
disp('fuzzy Controller table:e=[-3,+3],ec=[-3,+3]');%显示矩阵和数组内容
%推理
Ulist=zeros(7,7); %全零矩阵
for i=1:7
for j=1:7
e(i)=-4+i;
ec(j)=-4+j;
Ulist(i,j)=evalfis([e(i),ec(j)],a2); %完成模糊推理计算
end
end
% Ulist=ceil(Ulist) %朝正无穷方向取整
Ulist %朝正无穷方向取整
%画出模糊系统
figure(1); plotfis(a2);
figure(2);plotmf(a,'input',1);
figure(3);plotmf(a,'input',2);
figure(4);plotmf(a,'output',1);
a2的图像
输入1的图像
输入2的图像
输出的图片
规则:
1. If (e is NB) and (ec is NB) then (u is NB) (1)
2. If (e is NB) and (ec is NM) then (u is NB) (1)
3. If (e is NB) and (ec is NS) then (u is NB) (1)
4. If (e is NB) and (ec is Z) then (u is NM) (1)
5. If (e is NB) and (ec is PS) then (u is NM) (1)
6. If (e is NB) and (ec is PM) then (u is NS) (1)
7. If (e is NB) and (ec is PB) then (u is Z) (1)
8. If (e is NM) and (ec is NB) then (u is NB) (1)
9. If (e is NM) and (ec is NM) then (u is NM) (1)
10. If (e is NM) and (ec is NS) then (u is NM) (1)
11. If (e is NM) and (ec is Z) then (u is NM) (1)
12. If (e is NM) and (ec is PS) then (u is NS) (1)
13. If (e is NM) and (ec is PM) then (u is Z) (1)
14. If (e is NM) and (ec is PB) then (u is PS) (1)
15. If (e is NS) and (ec is NB) then (u is NB) (1)
16. If (e is NS) and (ec is NM) then (u is NM) (1)
17. If (e is NS) and (ec is NS) then (u is NS) (1)
18. If (e is NS) and (ec is Z) then (u is Z) (1)
19. If (e is NS) and (ec is PS) then (u is PS) (1)
20. If (e is NS) and (ec is PM) then (u is PM) (1)
21. If (e is NS) and (ec is PB) then (u is PB) (1)
22. If (e is Z) and (ec is NB) then (u is Z) (1)
23. If (e is Z) and (ec is NM) then (u is Z) (1)
24. If (e is Z) and (ec is NS) then (u is Z) (1)
25. If (e is Z) and (ec is Z) then (u is Z) (1)
26. If (e is Z) and (ec is PS) then (u is Z) (1)
27. If (e is Z) and (ec is PM) then (u is Z) (1)
28. If (e is Z) and (ec is PB) then (u is Z) (1)
29. If (e is PS) and (ec is NB) then (u is PB) (1)
30. If (e is PS) and (ec is NM) then (u is PM) (1)
31. If (e is PS) and (ec is NS) then (u is PS) (1)
32. If (e is PS) and (ec is Z) then (u is Z) (1)
33. If (e is PS) and (ec is PS) then (u is NS) (1)
34. If (e is PS) and (ec is PM) then (u is NM) (1)
35. If (e is PS) and (ec is PB) then (u is NB) (1)
36. If (e is PM) and (ec is NB) then (u is PM) (1)
37. If (e is PM) and (ec is NM) then (u is PM) (1)
38. If (e is PM) and (ec is NS) then (u is PM) (1)
39. If (e is PM) and (ec is Z) then (u is PM) (1)
40. If (e is PM) and (ec is PS) then (u is PM) (1)
41. If (e is PM) and (ec is PM) then (u is PM) (1)
42. If (e is PM) and (ec is PB) then (u is PM) (1)
43. If (e is PB) and (ec is NB) then (u is PB) (1)
44. If (e is PB) and (ec is NM) then (u is PB) (1)
45. If (e is PB) and (ec is NS) then (u is PB) (1)
46. If (e is PB) and (ec is Z) then (u is PB) (1)
47. If (e is PB) and (ec is PS) then (u is PB) (1)
48. If (e is PB) and (ec is PM) then (u is PB) (1)
49. If (e is PB) and (ec is PB) then (u is PB) (1)
后设定规则为:当其中一个输入含有PB时输出为PB
当其中一个输入含有PM时输出为PM
当输入中含有PS的时候,输出为另一个输入的反面,例如 另一个输入为PM 输出为NM;另一个输入为PB,输出为NB;
当输入含有一个Z时,输出都为Z
当有一个输入为NS时,输出结果为另一个输入;例如:另一个输入为NM,输出NM;
计算结果:
fuzzy Controller table:e=[-3,+3],ec=[-3,+3]
Ulist =
-3.6509 -3.6509 -2.3785 -2.1490 -1.8670 -1.0353 0.0000
-3.6509 -2.0164 -1.3807 -0.7102 -0.2308 0.1772 1.2000
-1.4580 -1.3807 -1.1120 -0.3249 0.0945 0.6144 1.4435
0.0272 -0.0000 -0.0000 0.0000 -0.0000 -0.0000 0.0369
1.4371 1.3632 1.1120 0.1497 -0.2308 -0.5460 -0.5233
2.6521 2.0320 1.3632 0.6688 0.4999 0.2858 0.8482
3.5296 3.5296 3.5296 3.5296 3.5296 3.5296 3.5296
计算结果分析:
例如第一行第一列 -3.6509 输入e(1)为-3 ec(1)为-3 经过模糊系统的计算为-3.6509 剩下几行几列以此类推。