模糊控制

模糊控制

一、代码实现

二、结果展示

三、总结

一、代码实现

 a=newfis('fuzzf');                 
f1=2; 
a=addvar(a,'input','e',[-2*f1,3*f1]);                   
a=addmf(a,'input',1,'NB','zmf',[-2*f1,2*f1]);          
a=addmf(a,'input',1,'NM','trimf',[-2*f1,-2*f1,0]);      
a=addmf(a,'input',1,'NS','trimf',[-2*f1,-1*f1,1*f1]); 
a=addmf(a,'input',1,'Z','trimf',[-3*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]);
 f2=2;
a=addvar(a,'input','ec',[-3*f2,4*f2]);            a=addmf(a,'input',2,'NB','zmf',[-3*f2,-1*f2]); 
a=addmf(a,'input',2,'NM','trimf',[-2*f2,-1*f2,0]);
a=addmf(a,'input',2,'NS','trimf',[-3*f2,-1*f2,1*f2]);
a=addmf(a,'input',2,'Z','trimf',[-2*f2,1,2*f2]);
a=addmf(a,'input',2,'PS','trimf',[-1*f2,1*f2,2*f2]);
a=addmf(a,'input',2,'PM','trimf',[0,1*f2,2*f2]);
a=addmf(a,'input',2,'PB','smf',[1*f2,2*f2]); 
f3=2;
a=addvar(a,'output','u',[-3*f3,3*f3]);                 
a=addmf(a,'output',1,'NB','zmf',[-2*f3,-1*f3]); 
a=addmf(a,'output',1,'NM','trimf',[-2*f3,0,1*f3]);
a=addmf(a,'output',1,'NS','trimf',[-3*f3,1,1*f3]);
a=addmf(a,'output',1,'Z','trimf',[-1*f3,0,2*f3]);
a=addmf(a,'output',1,'PS','trimf',[-1*f3,1*f3,2*f3]);
a=addmf(a,'output',1,'PM','trimf',[0,1*f3,2*f3]);
a=addmf(a,'output',1,'PB','smf',[1*f3,2*f3]);
rulelist=[1 2 1 1 1;
               1 2 1 1 1;	
               1 3 3 1 1;
               1 4 2 1 1;
               1 5 2 1 1;
               1 6 4 1 1;
               1 7 4 1 1;
          
               2 2 2 1 1;
               2 2 2 1 1;
               2 3 3 1 1;
               2 4 2 1 1;
               2 5 3 1 1;
               2 6 2 1 1;
               2 7 5 1 1;
               
               3 2 1 1 1;
               3 2 2 1 1;
               3 3 2 1 1;
               3 4 2 1 1;
               3 5 3 1 1;
               3 6 4 1 1;
               3 7 5 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 figure(1); plotfis(a2); figure(2);plotmf(a,'input',1); figure(3);plotmf(a,'input',2); figure(4);plotmf(a,'output',1);

  二、结果展示

e的隶属度函数

ec的隶属度函数

U的隶属度函数

模糊规则:

ans =

1. If (e is NB) and (ec is NM) 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 NS) (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 Z) (1)  

7. If (e is NB) and (ec is PB) then (u is Z) (1)  

8. If (e is NM) and (ec is NM) then (u is NM) (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 NS) (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 NM) (1)

14. If (e is NM) and (ec is PB) then (u is PS) (1)

15. If (e is NS) and (ec is NM) 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 NM) (1)

18. If (e is NS) and (ec is Z) then (u is NM) (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 Z) (1)

21. If (e is NS) and (ec is PB) then (u is PS) (1)

显示的矩阵和数组的内容

fuzzy Controller table:e=[-3,+3],ec=[-3,+3]

完成的模糊推理计算后的数据矩阵

Ulist =

   -1.8307   -2.3306   -1.8307   -1.1663   -0.5696   -0.5362   -0.4345

   -1.8289   -2.3550   -1.8289   -1.1663   -0.5691   -0.5041   -0.4345

   -1.8422   -2.2175   -1.8422   -1.1839   -0.5864   -0.5656   -0.4345

   -2.1515   -2.1515   -2.1515   -1.3332   -0.6721   -0.6721   -0.4345

   -2.0997   -2.0997   -2.0997   -1.6006   -0.7568   -0.7568   -0.6461

   -2.0614   -2.0614   -2.0614   -1.8161   -0.9071    0.0000    0.0000

   -2.0400   -2.0400   -2.0400   -1.9531   -0.9737    0.0000    0.0000

三、总结

本次试验有两个输入和一个输出,输入(e,ec),输出(U)。e的取值范围是[-4,6],ec的取值范围是[-6,8],u的取值范围是[-6,6],三个都有七个模糊集,模糊规则各有3个模糊集,所以最终一共有21个模糊规则。

原文地址:https://www.cnblogs.com/wyf-1999-1--6/p/11720503.html