模糊控制器设计 下载本文

% ---- 2009-5-17 ---- % ----------------------------- x=14;

% define input type in fuzzy zone y0 = gaussmf(x, [1 0]); y1 = gaussmf(x, [1 3]); y2 = gaussmf(x, [1 6]); y3 = gaussmf(x, [1 9]); y4 = gaussmf(x, [1 12]); y5= gaussmf(x, [1 15]); y6= gaussmf(x, [1 18]); a=[y0 y1 y2 y3 y4 y5 y6]; b=max(a);

% caculate input in fuzzy zone,get input_type and input_authorityvalue if x<=18 & x>=0 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;

13 / 27

elseif b==a(6) type='PM'; authorityvalue=y5; else b==a(7) type='PB'; authorityvalue=y6; end else if x>18 type='PB'; authorityvalue=1; elseif x<0 type='NB'; authorityvalue=1; end end type authorityvalue % caculate output by if type=='NB'

out=authorityvalue*15;

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

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

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

14 / 27

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

% if input is PS, then output is NS; elseif type=='PM' out=-authorityvalue*10;

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

out=-authorityvalue*15;

% if input is PB, then output is NB; end out 作业:

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

输入:-100-100范围内分为七个论域,NB NM NS ZE PS PM PB;隶属度函数满足高斯分布;

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

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

% % if input is NB, then output is PB; % % if input is NM, then output is PM; % % if input is NS, then output is PS; % % if input is ZE, then output is ZE; % % if input is PS, then output is NS; % % if input is PM, then output is NM; % % if input is PB, then output is NB;

15 / 27

程序为:

x1 = (-100:0.1:100)'; y0 = gaussmf(x1, [10 -100]); y1 = gaussmf(x1, [10 -66]); y2 = gaussmf(x1, [10 -33]); y3 = gaussmf(x1, [10 0]); y4 = gaussmf(x1, [10 33]); y5 = gaussmf(x1, [10 66]); y6 = gaussmf(x1, [10 100]); plot(x1,[y0 y1 y2 y3 y4 y5 y6]);

2.程序为: x=14;

% define input type in fuzzy zone y0 = gaussmf(x, [10 -100]); y1 = gaussmf(x, [10 -66]); y2 = gaussmf(x, [10 -33]);

16 / 27