模糊控制

应用MATLAB实现模糊控制@TOC
模糊控制理解参考: https://blog.csdn.net/weixin_38145317/article/details/82966901
https://blog.csdn.net/qq_34445388/article/details/79086584
模糊计算的基本流程:
模糊控制_第1张图片

1.MATLAB代码实现

###1.1改变输入输出变量e和ec的模糊隶属形态

%输入1
f1=1; 
a=addvar(a,'input','e',[-20*f1,20*f1]);               %e:error    
 %添加 e 的模糊语言变量
a=addmf(a,'input',1,'NB','zmf',[-20*f1,-10*f1]);     %z型     
 %添加 e 的模糊语言变量的隶属度函数(z型)
a=addmf(a,'input',1,'NM','trimf',[-20*f1,-9*f1,0]);      
  %隶属度函数为三角形
a=addmf(a,'input',1,'NS','trimf',[-20*f1,-6*f1,5*f1]); 
a=addmf(a,'input',1,'Z','trimf',[-10*f1,0,10*f1]); 
a=addmf(a,'input',1,'PS','trimf',[-8*f1,6*f1,20*f1]);
a=addmf(a,'input',1,'PM','trimf',[0,10*f1,20*f1]);
a=addmf(a,'input',1,'PB','smf',[8*f1,20*f1]); 

%输入2
f2=1;
a=addvar(a,'input','ec',[-22*f2,22*f2]);                   
 %添加 ec 的模糊语言变量
a=addmf(a,'input',2,'NB','zmf',[-22*f2,-8*f2]); 
a=addmf(a,'input',2,'NM','trimf',[-22*f2,-15*f2,0]);
a=addmf(a,'input',2,'NS','trimf',[-22*f2,-9*f2,10*f2]);
a=addmf(a,'input',2,'Z','trimf',[-15*f2,0,12*f2]);
a=addmf(a,'input',2,'PS','trimf',[-8*f2,8*f2,22*f2]);
a=addmf(a,'input',2,'PM','trimf',[0,15*f2,22*f2]);
a=addmf(a,'input',2,'PB','smf',[6*f2,22*f2]);

%输出
f3=1.5;
a=addvar(a,'output','u',[-30*f3,30*f3]);                 
   %添加 u 的模糊语言变量
a=addmf(a,'output',1,'NB','zmf',[-30*f3,-7*f3]); 
a=addmf(a,'output',1,'NM','trimf',[-30*f3,-15*f3,0]);
a=addmf(a,'output',1,'NS','trimf',[-18*f3,-9*f3,9*f3]);
a=addmf(a,'output',1,'Z','trimf',[-15*f3,0,15*f3]);
a=addmf(a,'output',1,'PS','trimf',[-10*f3,8*f3,30*f3]);
a=addmf(a,'output',1,'PM','trimf',[0,15*f3,30*f3]);
a=addmf(a,'output',1,'PB','smf',[11*f3,30*f3]);

1.2编辑模糊规则

%规则库
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 3 1 1;
               3 2 3 1 1;
               3 3 2 1 1;
               3 4 5 1 1;
               3 5 3 1 1;
               3 6 7 1 1;
               3 7 5 1 1;
               
               4 1 1 1 1;
               4 2 2 1 1;
               4 3 2 1 1;
               4 4 4 1 1;
               4 5 3 1 1;
               4 6 4 1 1;
               4 7 5 1 1;
               
               5 1 2 1 1;
               5 2 2 1 1;
               5 3 2 1 1;
               5 4 4 1 1;
               5 5 3 1 1;
               5 6 3 1 1;
               5 7 6 1 1;
               
               6 1 1 1 1;
               6 2 1 1 1;
               6 3 2 1 1;
               6 4 3 1 1;
               6 5 3 1 1;
               6 6 5 1 1;
               6 7 6 1 1;
               
               7 1 1 1 1;
               7 2 2 1 1;
               7 3 2 1 1;
               7 4 3 1 1;
               7 5 4 1 1;
               7 6 2 1 1;
               7 7 6 1 1;];

1.3实现模糊推理系统

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);

2.实现结果

2.1模糊规则

'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 NS) (1)’
‘16. If (e is NS) and (ec is NM) then (u is NS) (1)’
‘17. If (e is NS) and (ec is NS) then (u is NM) (1)’
'18. If (e is NS) and (ec is Z) then (u is PS) (1) ’
‘19. If (e is NS) and (ec is PS) then (u is NS) (1)’
‘20. If (e is NS) and (ec is PM) then (u is PB) (1)’
‘21. If (e is NS) and (ec is PB) then (u is PS) (1)’
'22. If (e is Z) and (ec is NB) then (u is NB) (1) ’
'23. If (e is Z) and (ec is NM) then (u is NM) (1) ’
'24. If (e is Z) and (ec is NS) then (u is NM) (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 NS) (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 PS) (1) ’
‘29. If (e is PS) and (ec is NB) then (u is NM) (1)’
‘30. If (e is PS) and (ec is NM) then (u is NM) (1)’
‘31. If (e is PS) and (ec is NS) then (u is NM) (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 NS) (1)’
‘35. If (e is PS) and (ec is PB) then (u is PM) (1)’
‘36. If (e is PM) and (ec is NB) then (u is NB) (1)’
‘37. If (e is PM) and (ec is NM) then (u is NB) (1)’
‘38. If (e is PM) and (ec is NS) then (u is NM) (1)’
'39. If (e is PM) and (ec is Z) then (u is NS) (1) ’
‘40. If (e is PM) and (ec is PS) then (u is NS) (1)’
‘41. If (e is PM) and (ec is PM) then (u is PS) (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 NB) (1)’
‘44. If (e is PB) and (ec is NM) then (u is NM) (1)’
‘45. If (e is PB) and (ec is NS) then (u is NM) (1)’
'46. If (e is PB) and (ec is Z) then (u is NS) (1) ’
'47. If (e is PB) and (ec is PS) then (u is Z) (1) ’
‘48. If (e is PB) and (ec is PM) then (u is NM) (1)’
‘49. If (e is PB) and (ec is PB) then (u is PM) (1)’

2.2模糊系统图像

模糊控制_第2张图片

3.结论

模糊控制优点:使用语言方法,不需要建立被控对象的精确的数学模型,只要对被控对象有大体了解,并总结出控制规则就能快速实现控制.;
模糊控制的缺点:.信息简单的模糊处理将导致系统的控制精度降低和动态品质变差;

你可能感兴趣的:(模糊控制)