模糊控制器设计 下载本文

y3 = gaussmf(x, [10 0]); y4 = gaussmf(x, [10 33]); y5 = gaussmf(x, [10 66]); y6 = gaussmf(x, [10 100]); a=[y0 y1 y2 y3 y4 y5 y6]; b=max(a);

% caculate input in fuzzy zone,get input_type and input_authorityvalue if x<=100 & x>=-100 if b==a(1) type='NB'; authorityvalue=y0; elseif b==a(2) type='NM'; authorityvalue=y1; elseif b==a(3) type='NS'; authorityvalue=y2; elseif b==a(4) type='ZE'; authorityvalue=y3; elseif b==a(5) type='PS'; authorityvalue=y4; elseif b==a(6) type='PM'; authorityvalue=y5; else b==a(7) type='PB';

17 / 27

authorityvalue=y6; end else

if x>100 type='PB'; authorityvalue=1; elseif x<-100 type='NB'; authorityvalue=1; end end type

authorityvalue % caculate output by if type=='NB'

out=authorityvalue*0;

% if input is NB, then output is PB; elseif type=='NM' out=authorityvalue*17;

% if input is NM, then output is PM; elseif type=='NS' out=authorityvalue*34;

% if input is NS, then output is PS; elseif type=='ZE' out=authorityvalue*51;

% if input is ZE, then output is ZE; elseif type=='PS' out=authorityvalue*68;

% if input is PS, then output is NS;

18 / 27

elseif type=='PM' out=authorityvalue*85;

% if input is PM, then output is NM; else type=='PB'

out=authorityvalue*100;

% if input is PB, then output is NB; end out 结果为: X=14 type =ZE

authorityvalue = 0.3753 out = 19.1409 X=-150 type =NB

authorityvalue =1 out =0

2. 设计一个模糊控制器,满足如下条件:

输入:-10-10范围内分为3个论域,NB ZE PB;隶属度函数满足高斯分布; 输入的误差:-2-2范围内分为3个论域,NB ZE PB;隶属度函数满足高斯分布;

输出:0到100范围内分为5个论域,NB NM ZE PM PB,隶属度函数为常数1。

模糊推理过程,output=(输入隶属度函数值+输入误差的隶属度函数值)/2*输出论域的中心值。 控制规则:

% % if input is NB and errorinput is NB, then output is NB; % % if input is NB and errorinput is ZE, then output is NM;

19 / 27

% % if input is NB and errorinput is PB, then output is ZE; % % if input is ZE and errorinput is NB, then output is NM; % % if input is ZE and errorinput is ZE, then output is ZE; % % if input is ZE and errorinput is PB, then output is PM; % % if input is PB and errorinput is NB, then output is ZE; % % if input is PB and errorinput is ZE, then output is PM; % % if input is PB and errorinput is PB, then output is PB; 1.输入为: 程序为: x1 = (-10:0.1:10)'; y0 = gaussmf(x1, [3 -10]); y1 = gaussmf(x1, [3 0]); y2 = gaussmf(x1, [3 10]); plot(x1,[y0 y1 y2]);

2.误差图: 程序为:

x1 = (-2:0.1:2)';

20 / 27