www.gusucode.com > 锅炉水位系统模糊控制的实例matlab源码程序 > code/qita/D_Domain/dflc.m
function [] = dflc( ) clear %隶属度函数 MF=[0 0 0 0.4 1;0 0.2 1 0.2 0;1 0.4 0 0 0]; %规则表 LAW=[1 1 2;1 2 3;2 3 3]; %初始化 e1(1)=0; de1(1)=0; u=30; y1(2)=0; for clk=1:200 y(clk)=y1(clk+1); time(clk)=clk/2; e1(clk+1)=u-y1(clk+1); de1(clk+1)=e1(clk+1)-e1(clk); %离散化e if e1(clk+1)<-18 e11=1; elseif e1(clk+1)<-6 e11=2; elseif e1(clk+1)<6 e11=3; elseif e1(clk+1)<18 e11=4; else e11=5; end %离散化de if de1(clk+1)<-36 de11=1; elseif de1(clk+1)<-12 de11=2; elseif de1(clk+1)<12 de11=3; elseif de1(clk+1)<36 de11=4; else de11=5; end %模糊推理 for i=1:3 for j=1:3 t=min(MF(i,e11),MF(j,de11)); for k=1:5 o((i-1)*3+j,k)=min(t,MF(LAW(j,i),k)); end end end for xx=1:5 t=0; for yy=1:9 t=max(o(yy,xx),t); end o(10,xx)=t; end %反模糊化 t=0; s=0; for x=1:5 t=t+o(10,x)*x; s=s+o(10,x); end u1(clk+2)=51*t/s-123; y1(clk+2)=exp(-0.05)*y1(clk+1)+(1-exp(-0.05))*u1(clk); end %画图 plot(time,y); xlabel('time'); ylabel('y'); [time' y']