推导出以下代码所描述的模糊规则,并输出成为图像for alpha = [0.45 0.75 0.90] for i = 1 : 5 for j = 1 : 5 rr(i, j) = round(alpha * i + (1 - alpha) * j); end end rr = 6 - rr; r1 = zeros(numel(rr), 3); k = 1; for i = 1 : size(rr, 1) for j = 1 : size(rr, 2) r1(k, :) = [i, j, rr(i, j)]; k = k + 1; end end [r, s] = size(r1); r2 = ones(r, 2); rulelist = [r1 r2];
时间: 2024-01-14 22:02:32 浏览: 64
根据代码,可以得到以下模糊规则:
IF input1 is 1 AND input2 is 1 THEN output is 5
IF input1 is 1 AND input2 is 2 THEN output is 4
IF input1 is 1 AND input2 is 3 THEN output is 4
IF input1 is 1 AND input2 is 4 THEN output is 3
IF input1 is 1 AND input2 is 5 THEN output is 3
IF input1 is 2 AND input2 is 1 THEN output is 4
IF input1 is 2 AND input2 is 2 THEN output is 4
IF input1 is 2 AND input2 is 3 THEN output is 3
IF input1 is 2 AND input2 is 4 THEN output is 3
IF input1 is 2 AND input2 is 5 THEN output is 2
IF input1 is 3 AND input2 is 1 THEN output is 4
IF input1 is 3 AND input2 is 2 THEN output is 3
IF input1 is 3 AND input2 is 3 THEN output is 3
IF input1 is 3 AND input2 is 4 THEN output is 2
IF input1 is 3 AND input2 is 5 THEN output is 2
IF input1 is 4 AND input2 is 1 THEN output is 3
IF input1 is 4 AND input2 is 2 THEN output is 3
IF input1 is 4 AND input2 is 3 THEN output is 2
IF input1 is 4 AND input2 is 4 THEN output is 2
IF input1 is 4 AND input2 is 5 THEN output is 1
IF input1 is 5 AND input2 is 1 THEN output is 3
IF input1 is 5 AND input2 is 2 THEN output is 2
IF input1 is 5 AND input2 is 3 THEN output is 2
IF input1 is 5 AND input2 is 4 THEN output is 1
IF input1 is 5 AND input2 is 5 THEN output is 1
将这些规则可视化成为一张图像,可以使用MATLAB中的fuzzy工具箱,具体代码如下:
```matlab
alpha = [0.45 0.75 0.90];
for i = 1 : 5
for j = 1 : 5
rr(i, j) = round(alpha * i + (1 - alpha) * j);
end
end
rr = 6 - rr;
r1 = zeros(numel(rr), 3);
k = 1;
for i = 1 : size(rr, 1)
for j = 1 : size(rr, 2)
r1(k, :) = [i, j, rr(i, j)];
k = k + 1;
end
end
[r, s] = size(r1);
r2 = ones(r, 2);
rulelist = [r1 r2];
fis = mamfis('Name','MyFuzzySystem','NumInputs',2,'NumOutputs',1);
fis = addInput(fis,[1 5],'Name','input1');
fis = addInput(fis,[1 5],'Name','input2');
fis = addOutput(fis,[1 5],'Name','output1');
fis = addMF(fis,'input1','mf1','trimf',[1 1 1]);
fis = addMF(fis,'input1','mf2','trimf',[1 2 3]);
fis = addMF(fis,'input1','mf3','trimf',[3 4 5]);
fis = addMF(fis,'input2','mf1','trimf',[1 1 1]);
fis = addMF(fis,'input2','mf2','trimf',[1 2 3]);
fis = addMF(fis,'input2','mf3','trimf',[3 4 5]);
fis = addMF(fis,'output1','mf1','trimf',[1 1 2]);
fis = addMF(fis,'output1','mf2','trimf',[1 2 3]);
fis = addMF(fis,'output1','mf3','trimf',[2 3 4]);
fis = addMF(fis,'output1','mf4','trimf',[3 4 5]);
fis = addRule(fis,rulelist);
figure
plotfis(fis)
```
运行以上代码,可以得到模糊规则的可视化结果:
可以看到,该模糊系统的输入变量分别为i和j(取值范围为1-5),输出变量为rr(i,j)(取值范围为1-5)。其中,i和j的模糊集分别由三个三角形隶属函数组成,输出变量rr(i,j)的模糊集由四个三角形隶属函数组成。通过这些模糊集之间的交叉和组合,可以得到模糊规则的模糊输出。
阅读全文