clear
xl=-4;
h=0.01;
xr=4;
x=xl:h:xr;
y1=tri_l(x,-3.2,2.4);
y2=trap_a(x,2.4,0.8,-0.8,0);
y3=tri_s(x,0,0.8);
y4=trap_a(x,0.8,2.4,0.8,0);
y5=tri_r(x,3.2,2.4);
figure
plot(x,y1)
hold on
plot(x,y2)
plot(x,y3)
plot(x,y4)
plot(x,y5)
set(gca,'Fontsize',12)
title('Membership functions for {\it x}_1','Fontsize',12)
xlabel('Universe of discourse','Fontsize',12)
ylabel('Membership','Fontsize',12)
hold off
%pause
yl=-10;
hh=0.01;
yr=10;
y=yl:hh:yr;
z1=tri_l(y,-8,6);
z2=trap_a(y,6,2,-2,0);
z3=tri_s(y,0,2);
z4=trap_a(y,2,6,2,0);
z5=tri_r(y,8,6);
figure
plot(y,z1)
hold on
plot(y,z2)
plot(y,z3)
plot(y,z4)
plot(y,z5)
set(gca,'Fontsize',12)
title('Membership functions of {\it x}_2','Fontsize',12)
xlabel('Universe of discourse','Fontsize',12)
ylabel('Membership','Fontsize',12)
hold off
%pause
ol=-15;
ho=0.01;
or=15;
o=ol:ho:or;
%mo=[-2.5 -1 0 1 2.5];
%so=[1 1 1 1 1];
o1=tri_l(o,-15,8);
o2=trap_a(o,8,2.5,-7,0);
o3=trap_a(o,2.5,3,-4.5,0);
o4=trap_a(o,1.5,0.8,-1.5,0);
o5=trap_a(o,.35,.45,-0.65,0);
o6=trap_a(o,.45,.2,-0.2,0);
o7=trap_a(o,.2,.2,0,0);
o8=trap_a(o,.2,.45,0.2,0);
o9=trap_a(o,.45,.35,0.65,0);
o10=trap_a(o,0.8,1.5,1.5,0);
o11=trap_a(o,3,2.5,4.5,0);
o12=trap_a(o,2.5,8,7,0);
o13=tri_r(o,15,8);
figure
plot(o,o1)
hold on
plot(o,o2)
plot(o,o3)
plot(o,o4)
plot(o,o5)
plot(o,o6)
plot(o,o7)
plot(o,o8)
plot(o,o9)
plot(o,o10)
plot(o,o11)
plot(o,o12)
plot(o,o13)
set(gca,'Fontsize',12)
title('Membership functions for {\it u}','Fontsize',12)
xlabel('Universe of discourse','Fontsize',12)
ylabel('Membership','Fontsize',12)
hold off
%pause
x1=linspace(-4,4,22);
x2=linspace(-10,10,22);
%fc=input('Do you want to continue?---Y/N ','s');
%if (fc=='Y')|(fc=='y')
for j = 1:22
  for i = 1:22
w(1)=tri_l(x2(j),-8,6)*tri_l(x1(i),-3.2,2.4);
w(2)=tri_l(x2(j),-8,6)*trap_a(x1(i),2.4,0.8,-0.8,0);
w(3)=tri_l(x2(j),-8,6)*tri_s(x1(i),0,0.8);
w(4)=tri_l(x2(j),-8,6)*trap_a(x1(i),0.8,2.4,0.8,0);
w(5)=tri_l(x2(j),-8,6)*tri_r(x1(i),3.2,2.4);
%----------------------------------------------------------------
w(6)=trap_a(x2(j),6,2,-2,0)*tri_l(x1(i),-3.2,2.4);
w(7)=trap_a(x2(j),6,2,-2,0)*trap_a(x1(i),2.4,0.8,-0.8,0);
w(8)=trap_a(x2(j),6,2,-2,0)*tri_s(x1(i),0,0.8);
w(9)=trap_a(x2(j),6,2,-2,0)*trap_a(x1(i),0.8,2.4,0.8,0);
w(10)=trap_a(x2(j),6,2,-2,0)*tri_r(x1(i),3.2,2.4);
%----------------------------------------------------------------
w(11)=tri_s(x2(j),0,2)*tri_l(x1(i),-3.2,2.4);
w(12)=tri_s(x2(j),0,2)*trap_a(x1(i),2.4,0.8,-0.8,0);
w(13)=tri_s(x2(j),0,2)*tri_s(x1(i),0,0.8);
w(14)=tri_s(x2(j),0,2)*trap_a(x1(i),0.8,2.4,0.8,0);
w(15)=tri_s(x2(j),0,2)*tri_r(x1(i),3.2,2.4);
%----------------------------------------------------------------
w(16)=trap_a(x2(j),2,6,2,0)*tri_l(x1(i),-3.2,2.4);
w(17)=trap_a(x2(j),2,6,2,0)*trap_a(x1(i),2.4,0.8,-0.8,0);
w(18)=trap_a(x2(j),2,6,2,0)*tri_s(x1(i),0,0.8);
w(19)=trap_a(x2(j),2,6,2,0)*trap_a(x1(i),0.8,2.4,0.8,0);
w(20)=trap_a(x2(j),2,6,2,0)*tri_r(x1(i),3.2,2.4);
%----------------------------------------------------------------
w(21)=tri_r(x2(j),8,6)*tri_l(x1(i),-3.2,2.4);
w(22)=tri_r(x2(j),8,6)*trap_a(x1(i),2.4,0.8,-0.8,0);
w(23)=tri_r(x2(j),8,6)*tri_s(x1(i),0,0.8);
w(24)=tri_r(x2(j),8,6)*trap_a(x1(i),0.8,2.4,0.8,0);
w(25)=tri_r(x2(j),8,6)*tri_r(x1(i),3.2,2.4);
%----------------------------------------------------------------
ws(1)=w(1)*15;
ws(2)=w(2)*4.5;
ws(3)=w(3)*4.5;
ws(4)=w(4)*4.5;
ws(5)=w(5)*15;
%---------------------
ws(6)=w(6)*7;
ws(7)=w(7)*1.5;
ws(8)=w(8)*0.65;
ws(9)=w(9)*0.65;
ws(10)=w(10)*4.5;
%---------------------
ws(11)=w(11)*1.5;
ws(12)=w(12)*0.2;
ws(13)=w(13)*0;
ws(14)=w(14)*(-0.2);
ws(15)=w(15)*(-1.5);
%---------------------
ws(16)=w(16)*(-4.5);
ws(17)=w(17)*(-0.65);
ws(18)=w(18)*(-0.65);
ws(19)=w(19)*(-1.5);
ws(20)=w(20)*(-7);
%---------------------
ws(21)=w(21)*(-15);
ws(22)=w(22)*(-4.5);
ws(23)=w(23)*(-4.5);
ws(24)=w(24)*(-4.5);
ws(25)=w(25)*(-15);
%---------------------
m_cs(j,i)=sum(ws)/sum(w);
end
end
m_cs;
[X1,X2] = meshgrid(x1,x2);
%gu=[-160 30];
figure
mesh(X1,X2,m_cs)
view(-120,30)
hold on
set(gca,'Fontsize',12)
title('Control surface {\it u}={\it f}({\it x}_1,{\it x}_2)','Fontsize',12)
xlabel('{\it x}_1','Fontsize',12)
ylabel('{\it x}_2','Fontsize',12)
zlabel('{\it u}','Fontsize',12)
%pause
hold off
%gu=[-140 30];
%figure
%mesh(m_cs,gu)
%hold on
%grid
%set(gca,'Fontsize',12)
%title('Control surface {\it u}={\it f}({\it x}_1,{\it x}_2)','Fontsize',12)
%xlabel('{\it x}_1','Fontsize',12)
%ylabel('{\it x}_2','Fontsize',12)
%hold off
%pause
%gu=[-160 30];
%figure
%axis([-4 4 -10 10 -15 15])
%hold on
%mesh(m_cs,gu)
%grid
%set(gca,'Fontsize',12)
%title('Control surface {\it u}={\it f}({\it x}_1,{\it x}_2)','Fontsize',12)
%xlabel('{\it x}_1','Fontsize',12)
%ylabel('{\it x}_2','Fontsize',12)
%zlabel('{\it u}','Fontsize',12)
%hold off
figure
axis([-5 5 -10 10])
hold
grid
set(gca,'Fontsize',12)
title('Phase portrait of the closed-loop system','Fontsize',12)
xlabel('{\it x}_1','Fontsize',12)
ylabel('{\it x}_2','Fontsize',12)
TST4F7s