clear
Ca=30000;
l1=1.2;
l2=1.22;
m=1280;
Iz=2500;
U=18.3;
A=[-(2*Ca+2*Ca)/(m*U) 0 -U-(2*Ca*l1-2*Ca*l2)/(m*U) 0;...
0 0 1 0;-(2*l1*Ca-2*l2*Ca)/(Iz*U) 0 -(2*l1^2*Ca+2*l2^2*Ca)/(Iz*U) 0;-1 -U 0 0];
b=[2*Ca/m 0 2*l1*Ca/Iz 0]';
c=[0 0 0 1];
%xl=input('Change-in-error xl=')
%h=input('step size h=')
%xr=input('xr=')
%x=xl:h:xr;
%mc=input('Change-in-error membership functions median vector mc=')
%sc=input('Change-in-error membership function spread vector sc=')
xl=-0.06;
h=0.0001;
xr=0.06;
x=xl:h:xr;
mc=[-0.05 -0.025 0 0.025 0.05];
sc=[0.025 0.025 0.025 0.025 0.025];
y1=tri_l(x,mc(1),sc(1));
y2=tri_s(x,mc(2),sc(2));
y3=tri_s(x,mc(3),sc(3));
y4=tri_s(x,mc(4),sc(4));
y5=tri_r(x,mc(5),sc(5));
%plot(x,y1,'-',x,y2,'x',x,y3,'--',x,y4,'*',x,y5,':')
plot(x,y1)
hold on
plot(x,y2)
plot(x,y3)
plot(x,y4)
plot(x,y5)
title('CHANGE-IN-ERROR membership functions','Fontsize',12)
xlabel('Universe of discourse','Fontsize',12)
ylabel('Membership','Fontsize',12)
set(gca,'Fontsize',12)
grid
hold off
%pause
%yl=input('Error yl=')
%hh=input('step size now is hh=')
%yr=input('yr=')
%y=yl:hh:yr;
%me=input('Error membership functions median vector me=')
%se=input('Error membership function spread vector se=')
me=[-0.4 -0.2 0 0.2 0.4];
se=[0.1 0.2 0.2 0.2 0.1];
yl=-0.5;
hh=0.001;
yr=0.5;
y=yl:hh:yr;
z1=tri_l(y,me(1),se(1));
z2=tri_s(y,me(2),se(2));
z3=tri_s(y,me(3),se(3));
z4=tri_s(y,me(4),se(4));
z5=tri_r(y,me(5),se(5));
%plot(y,z1,'-',y,z2,'x',y,z3,'--',y,z4,'*',y,z5,':')
figure
plot(y,z1)
hold on
plot(y,z2)
plot(y,z3)
plot(y,z4)
plot(y,z5)
title('ERROR membership functions','Fontsize',12)
xlabel('Universe of discourse','Fontsize',12)
ylabel('Membership','Fontsize',12)
set(gca,'Fontsize',12)
grid
hold off
%pause
%ol=input('Output ol=')
%ho=input('step size now is ho=')
%or=input('or=')
%o=ol:ho:or;
%mo=input('CONTROLmembership functions median vector mo=')
%so=input('CONTROL membership function spread vector so=')
ol=-3;
ho=0.01;
or=3;
o=ol:ho:or;
mo=[-2.5 -1 0 1 2.5];
so=[1 1 1 1 1];
o1=tri_l(o,mo(1),so(1));
o2=tri_s(o,mo(2),so(2));
o3=tri_s(o,mo(3),so(3));
o4=tri_s(o,mo(4),so(4));
o5=tri_r(o,mo(5),so(5));
%plot(o,o1,'-',o,o2,'x',o,o3,'--',o,o4,'*',o,o5,':')
figure
plot(o,o1)
hold on
plot(o,o2)
plot(o,o3)
plot(o,o4)
plot(o,o5)
title('CONTROL membership functions','Fontsize',12)
xlabel('Universe of discourse','Fontsize',12)
ylabel('Membership','Fontsize',12)
set(gca,'Fontsize',12)
grid
hold off
%pause
%ec=input('Quantized change-in-error ec=')
%e=input('Quantized error e=')
ec=linspace(-0.06,0.06,22);
e=linspace(-0.5,0.5,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(e(j),me(1),se(1))*tri_l(ec(i),mc(1),sc(1))/so(1);
w(2)=tri_l(e(j),me(1),se(1))*tri_s(ec(i),mc(2),sc(2))/so(1);
w(3)=tri_l(e(j),me(1),se(1))*tri_s(ec(i),mc(3),sc(3))/so(1);
w(4)=tri_l(e(j),me(1),se(1))*tri_s(ec(i),mc(4),sc(4))/so(2);
w(5)=tri_l(e(j),me(1),se(1))*tri_r(ec(i),mc(5),sc(5))/so(3);
%----------------------------------------------------------------
w(6)=tri_s(e(j),me(2),se(2))*tri_l(ec(i),mc(1),sc(1))/so(1);
w(7)=tri_s(e(j),me(2),se(2))*tri_s(ec(i),mc(2),sc(2))/so(1);
w(8)=tri_s(e(j),me(2),se(2))*tri_s(ec(i),mc(3),sc(3))/so(2);
w(9)=tri_s(e(j),me(2),se(2))*tri_s(ec(i),mc(4),sc(4))/so(3);
w(10)=tri_s(e(j),me(2),se(2))*tri_r(ec(i),mc(5),sc(5))/so(4);
%----------------------------------------------------------------
w(11)=tri_s(e(j),me(3),se(3))*tri_l(ec(i),mc(1),sc(1))/so(2);
w(12)=tri_s(e(j),me(3),se(3))*tri_s(ec(i),mc(2),sc(2))/so(2);
w(13)=tri_s(e(j),me(3),se(3))*tri_s(ec(i),mc(3),sc(3))/so(3);
w(14)=tri_s(e(j),me(3),se(3))*tri_s(ec(i),mc(4),sc(4))/so(4);
w(15)=tri_s(e(j),me(3),se(3))*tri_r(ec(i),mc(5),sc(5))/so(4);
%----------------------------------------------------------------
w(16)=tri_s(e(j),me(4),se(4))*tri_l(ec(i),mc(1),sc(1))/so(2);
w(17)=tri_s(e(j),me(4),se(4))*tri_s(ec(i),mc(2),sc(2))/so(3);
w(18)=tri_s(e(j),me(4),se(4))*tri_s(ec(i),mc(3),sc(3))/so(4);
w(19)=tri_s(e(j),me(4),se(4))*tri_s(ec(i),mc(4),sc(4))/so(5);
w(20)=tri_s(e(j),me(4),se(4))*tri_r(ec(i),mc(5),sc(5))/so(5);
%----------------------------------------------------------------
w(21)=tri_r(e(j),me(5),se(5))*tri_l(ec(i),mc(1),sc(1))/so(3);
w(22)=tri_r(e(j),me(5),se(5))*tri_s(ec(i),mc(2),sc(2))/so(4);
w(23)=tri_r(e(j),me(5),se(5))*tri_s(ec(i),mc(3),sc(3))/so(5);
w(24)=tri_r(e(j),me(5),se(5))*tri_s(ec(i),mc(4),sc(4))/so(5);
w(25)=tri_r(e(j),me(5),se(5))*tri_r(ec(i),mc(5),sc(5))/so(5);
%----------------------------------------------------------------
ws(1)=w(1)*mo(1);
ws(2)=w(2)*mo(1);
ws(3)=w(3)*mo(1);
ws(4)=w(4)*mo(2);
ws(5)=w(5)*mo(3);
%---------------------
ws(6)=w(6)*mo(1);
ws(7)=w(7)*mo(1);
ws(8)=w(8)*mo(2);
ws(9)=w(9)*mo(3);
ws(10)=w(10)*mo(4);
%---------------------
ws(11)=w(11)*mo(2);
ws(12)=w(12)*mo(2);
ws(13)=w(13)*mo(3);
ws(14)=w(14)*mo(4);
ws(15)=w(15)*mo(4);
%---------------------
ws(16)=w(16)*mo(2);
ws(17)=w(17)*mo(3);
ws(18)=w(18)*mo(4);
ws(19)=w(19)*mo(5);
ws(20)=w(20)*mo(5);
%---------------------
ws(21)=w(21)*mo(3);
ws(22)=w(22)*mo(4);
ws(23)=w(23)*mo(5);
ws(24)=w(24)*mo(5);
ws(25)=w(25)*mo(5);
%---------------------
v(j,i)=sum(ws)/sum(w);
end
end
v;
%M=[0 ec
%   e' v]
%pause
figure
[EC,E] = meshgrid(ec,e);
%gu=[-120 45];
%mesh(v,gu)
mesh(EC,E,v)
title('Control surface {\it v}={\it f}({\it de/dt},{\it e})','Fontsize',12)
set(gca,'Fontsize',12)
xlabel('\it de/dt','Fontsize',12)
ylabel('\it e','Fontsize',12)
zlabel('\it u','Fontsize',12)
%pause
%gu=[-140 45];
%mesh(v,gu)
%title('Nonlinear function v=f(ec,e)')
%pause
%gu=[-160 45];
%mesh(v,gu)
%title('Nonlinear function v=f(ec,e)')
%else
%end
hold off
figure
hold
title('Plot of {\it Y} versus {\it X}','Fontsize',12)
xlabel('\it X','Fontsize',12)
ylabel('\it Y','Fontsize',12)
set(gca,'Fontsize',12)
example_8_8