洗衣机的模糊控制MATLAB仿真
污泥和油脂隶属函数设计仿真程序
%Define N+1triangle membership function
clear all;
close all;
N=2;
x=0:0.1:100;
for i=1:N+1
f(i)=100/N*(i-1);
end
u=trimf(x,[f(1),f(1),f(2)]);
figure(1);
plot(x,u);
for j=2:N
u=trimf(x,[f(j-1),f(j),f(j+1)]);
hold on;
plot(x,u);
end
u=trimf(x,[f(N),f(N+1),f(N+1)]);
hold on;
plot(x,u);
xlabel('x');
ylabel('Degree of membership');
洗涤时间隶属函数设计仿真程序
%Define N+1 triangle membership function
clear all;
close all;
z=0:0.1:60;
u=trimf(z,[0,0,10]);
figure(1);
plot(z,u);
u=trimf(z,[0,10,25]);
hold on;
plot(z,u);
u=trimf(z,[10,25,40]);
hold on;
plot(z,u);
u=trimf(z,[25,40,60]);
hold on;
plot(z,u);
u=trimf(z,[40,60,60]);
hold on;
plot(z,u);
xlabel('z');
ylabel('Degree of membership');
洗衣机模糊控制系统仿真程序
clear all;
close all;
a=newfis('fuzz-wash');
a=addvar(a,'input','x',[0,100]); %Fuzzy Stain
a=addmf(a,'input',1,'SD','trimf',[0,0,50]);
a=addmf(a,'input',1,'MD','trimf',[0,50,100]);
a=addmf(a,'input',1,'LD','trimf',[50,100,100]);
a=addvar(a,'input','y',[0,100]); %Fuzzy Axunge
a=addmf(a,'input',2,'NG','trimf',[0,0,50]);
a=addmf(a,'input',2,'MG','trimf',[0,50,100]);
a=addmf(a,'input',2,'LG','trimf',[50,100,100]);
a=addvar(a,'output','z',[0,60]); %Fuzzy Time
a=addmf(a,'output',1,'VS','trimf',[0,0,10]);
a=addmf(a,'output',1,'S','trimf',[0,10,25]);
a=addmf(a,'output',1,'M','trimf',[10,25,40]);
a=addmf(a,'output',1,'L','trimf',[25,40,60]);
a=addmf(a,'output',1,'VL','trimf',[40,60,60]);
rulelist=[1 1 1 1 1;1 2 3 1 1;1 3 4 1 1;
2 1 2 1 1;2 2 3 1 1;2 3 4 1 1;
3 1 3 1 1;3 2 4 1 1;3 3 5 1 1;]
a=addrule(a,rulelist);
showrule(a)
a1=setfis(a,'DefuzzMethod','mom');
writefis(a1,'wash');
a2=readfis('wash');
figure(1);
plotfis(a2);
figure(2);
plotmf(a,'input',1);
figure(3);
plotmf(a,'input',2);
figure(4);
plotmf(a,'output',1);
ruleview('wash'); %Dynamic Simulation
x=60;
y=70;
z=evalfis([x,y],a2) %Using fuzzy inference
运行效果