close all
clear all
a=newfis('fuzzf')
f1=1
a=addvar(a,'input','e',[-3*f1,3*f1])
a=addmf(a,'input',1,'NB','zmf',[-3*f1,-1*f1])
a=addmf(a,'input',1,'NM','trimf',[-3*f1,-2*f1,0])
a=addmf(a,'input',1,'NS','trimf',[-3*f1,-1*f1,1*f1])
a=addmf(a,'input',1,'Z','trimf',[-2*f1,0,2*f1])
a=addmf(a,'input',1,'PS','trimf',[-1*f1,1*f1,3*f1])
a=addmf(a,'input',1,'PM','trimf',[0,2*f1,3*f1])
a=addmf(a,'input',1,'PB','smf',[1*f1,3*f1])
f2=1
a=addvar(a,'input','ec',[-3*f2,3*f2])
a=addmf(a,'input',2,'NB','zmf',[-3*f2,-1*f2])
a=addmf(a,'input',2,'NM','trimf',[-3*f2,-2*f2,0])
a=addmf(a,'input',2,'NS','trimf',[-3*f2,-1*f2,1*f2])
a=addmf(a,'input',2,'Z','trimf',[-2*f2,0,2*f2])
a=addmf(a,'input',2,'PS','trimf',[-1*f2,1*f2,3*f2])
a=addmf(a,'input',2,'PM','trimf',[0,2*f2,3*f2])
a=addmf(a,'input',2,'PB','smf',[1*f2,3*f2])
f3=1.5
a=addvar(a,'output','u',[-3*f3,3*f3])
a=addmf(a,'output',1,'NB','zmf',[-3*f3,-1*f3])
a=addmf(a,'output',1,'NM','trimf',[-3*f3,-2*f3,0])
a=addmf(a,'output',1,'NS','trimf',[-3*f3,-1*f3,1*f3])
a=addmf(a,'output',1,'Z','trimf',[-2*f3,0,2*f3])
a=addmf(a,'output',1,'PS','trimf',[-1*f3,1*f3,3*f3])
a=addmf(a,'output',1,'PM','trimf',[0,2*f3,3*f3])
a=addmf(a,'output',1,'PB','smf',[1*f3,3*f3])
rulelist=[1 1 1 1 1
1 2 1 1 1
1 3 2 1 1
1 4 2 1 1
1 5 3 1 1
1 6 3 1 1
1 7 4 1 1
2 1 1 1 1
2 2 2 1 1
2 3 2 1 1
2 4 3 1 1
2 5 3 1 1
2 6 4 1 1
2 7 5 1 1
3 1 2 1 1
3 2 2 1 1
3 3 3 1 1
3 4 3 1 1
3 5 4 1 1
3 6 5 1 1
3 7 5 1 1
4 1 2 1 1
4 2 3 1 1
4 3 3 1 1
4 4 4 1 1
4 5 5 1 1
4 6 5 1 1
4 7 6 1 1
5 1 3 1 1
5 2 3 1 1
5 3 4 1 1
5 4 5 1 1
5 5 5 1 1
5 6 6 1 1
5 7 6 1 1
6 1 3 1 1
6 2 4 1 1
6 3 5 1 1
6 4 5 1 1
6 5 6 1 1
6 6 6 1 1
6 7 7 1 1
7 1 4 1 1
7 2 5 1 1
7 3 5 1 1
7 4 6 1 1
7 5 6 1 1
7 6 7 1 1
7 7 7 1 1]
a=addrule(a,rulelist)
a1=setfis(a,'DefuzzMethod','mom')%Defuzzy
writefis(a1,'fuzzf')
a2=readfis('fuzzf')
Ulist=zeros(7,7)
for i=1:7
for j=1:7
e(i)=-4+i
ec(j)=-4+j
Ulist(i,j)=evalfis([e(i),ec(j)],a2)
end
end
figure(1)
plotfis(a2)
figure(2)
plotmf(a,'input',1)
figure(3)
plotmf(a,'input',2)
figure(4)
plotmf(a,'output',1)
这里简单说明一下:首先是编写2个输入,1个输出的隶属度函数;接下来的是模糊规则,一共49条;然后用解模糊函数得出控制量U,这里输出的U就直接是精确量了,解模糊用到得规则是取隶属度最大的那个数即MOM算法。
显示的三个图形窗口分别是:模糊控制器内部原理图,以及2个输入,1个输出的隶属度函数图。
被控对象:function dx=liuxiaomodel(t,x)a1=-1.0
a2=1.0
a3=0.0
l=0.5
j1=1.0
j2=1.0
j3=2.0
delta_1=0.5*x(2)+1.5*sign(x(2))
delta_2=0.5*x(4)+1.5*sign(x(4))
delta_3=0.5*x(6)+1.5*sign(x(6))
dx=zeros(9,1)
dx(1)=x(2)
dx(2)=1/j1*(a1*x(4)*x(6)-l*x(4)+x(7)+delta_1)
dx(3)=x(4)
dx(4)=1/j2*(a2*x(2)*x(6)-l*x(2)+x(8)+delta_2)
dx(5)=x(6)
dx(6)=1/j3*(a3*x(2)*x(4)+x(9)+delta_3)
dx(7)=0
dx(8)=0
dx(9)=0
dx=[dx(1)dx(2)dx(3)dx(4)dx(5)dx(6)dx(7)dx(8)dx(9)]
end
控制程序
clear
tic
ts=0.01
kk=1000
tt=0:ts:ts*(kk-1)
x10=0.01
x20=0.0
x30=0.01
x40=0.0
x50=0.01
x60=0.0
gamma=-500
thea_10=0.5
thea_20=0.5
thea_30=0.5
for ii=1:1:kk
xd=sin(pi*ts*(ii-1))
dxd=pi*cos(pi*ts*(ii-1))
ddxd=-1*pi*pi*sin(pi*ts*(ii-1))
e10=x10-xd
de10=x20-dxd
q10=dxd-15*e10
dq10=ddxd-15*de10
s10=de10+15*e10
e30=x30-xd
de30=x40-dxd
q30=dxd-15*e30
dq30=ddxd-15*de30
s30=de30+15*e30
e50=x50-xd
de50=x60-dxd
q50=dxd-15*e50
dq50=ddxd-15*de50
s50=de50+15*e50
thea1p=thea_10+gamma*dq10*s10*ts
thea2p=thea_20+gamma*dq30*s30*ts
thea3p=thea_30+gamma*dq50*s50*ts
% x70=thea1p*dq10+x40*x60+0.5*x40-15*s10-2.01*sign(s10)
% x80=thea2p*dq30-x20*x60+0.5*x20-15*s30-2.01*sign(s30)
% x90=thea3p*dq50+x20*x40-15*s50-2.01*sign(s50)
x70=dq10+x40*x60+0.5*x40-15*s10-2.01*sign(s10)
x80=dq30+x20*x60+0.5*x20-15*s30-2.01*sign(s30)
x90=dq50+x20*x40-15*s50-2.01*sign(s50)
[t,x]=ode45('liuxiaomodel',[(ii-1)*ts,ii*ts],[x10x20x30x40x50x60x70x80x90])
[m,n]=size(x)
x10=x(m,1)
x20=x(m,2)
x30=x(m,2)
x40=x(m,2)
x50=x(m,2)
x60=x(m,2)
% thea_10=thea1p
% thea_20=thea2p
% thea_30=thea3p
out1(ii)=x10
out2(ii)=x20
out3(ii)=x30
out4(ii)=x40
out5(ii)=x50
out6(ii)=x60
out7(ii)=x70
out8(ii)=thea1p
end
figure(1),plot(tt,out1),grid
figure(2),plot(tt,out3),grid
figure(3),plot(tt,out5),grid
figure(4),plot(tt,out7),grid
figure(5),plot(tt,out8),grid
toc
采用注释部分没有运行结果,如同进入死循环为何?求教!!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)