clc
clear
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%% Example 2
A11=[0 1; -44.75 -20]; A12=[0 1; -41.19 -20];
A21=[0 1; -42.55 -20]; A22=[0 1; -38.99 -20];
Atau11=[0 0; -1 -0.4]; Atau12=Atau11;
Atau21=[0 0; -1.2 -0.5]; Atau22=Atau21;
B12=[0 0; 0.8 0]; B21=[0 0; 1 0];
C11=[0; 0.5]; C12=C11; C21=[0; 0.4]; C22=C21;
D11=[1 0]; D12=D11; D21=D11; D22=D11;
Dtau11=[0.1 0]; Dtau12=Dtau11;
Dtau21=[0.08 0]; Dtau22=Dtau21;
G11=[0 1]; G12=G11; G21=G11; G22=G11; E11=0; E12=0; E21=0; E22=0;
%gamma=1; %%%%% for simulation
%%%%%%%%%%%%%
Af11=[-2.4409 0.7508; -193.4481 -36.0634];Af12=[ -2.4704 0.7714; -196.6598 -36.5871];
Af21=[-1.1664 0.8471; -163.0604 -34.7050];Af22=[-1.1757 0.8727; -166.4750 -35.1970];
Bf11=[-1.8255; -137.2169];Bf12=[-1.8850; -145.3440];
Bf21=[-0.6479; -113.0800];Bf22=[-0.6873; -121.2615];
Gf11=[0.0788 -0.4708];Gf12=[0.0431 -0.4466];
Gf21=[0.0825 -0.4523];Gf22=[0.0454 -0.4286];
%%%%%%%%%%%%%
A111=[A11, zeros(2); Bf11*D11, Af11]; A112=[A11, zeros(2); Bf12*D11, Af12];
A121=[A12, zeros(2); Bf11*D12, Af11]; A122=[A12, zeros(2); Bf12*D12, Af12];
Atau111=[Atau11, zeros(2); Bf11*Dtau11, zeros(2)]; Atau112=[Atau11, zeros(2); Bf12*Dtau11, zeros(2)];
Atau121=[Atau12, zeros(2); Bf11*Dtau12, zeros(2)]; Atau122=[Atau12, zeros(2); Bf12*Dtau12, zeros(2)];
C111=[C11; Bf11*E11]; C112=[C11; Bf12*E11];
C121=[C12; Bf11*E12]; C122=[C12; Bf12*E12];
G111=[G11, -Gf11]; G112=[G11, -Gf12]; G121=[G12, -Gf11]; G122=[G12, -Gf12];
M21=[B21, zeros(2); zeros(2), zeros(2)];
A211=[A21, zeros(2); Bf21*D21, Af21]; A212=[A21, zeros(2); Bf22*D21, Af22];
A221=[A22, zeros(2); Bf21*D22, Af21]; A222=[A22, zeros(2); Bf22*D22, Af22];
Atau211=[Atau21, zeros(2); Bf21*Dtau21, zeros(2)]; Atau212=[Atau21, zeros(2); Bf22*Dtau21, zeros(2)];
Atau221=[Atau22, zeros(2); Bf21*Dtau22, zeros(2)]; Atau222=[Atau22, zeros(2); Bf22*Dtau22, zeros(2)];
C211=[C21; Bf21*E21]; C212=[C21; Bf22*E21];
C221=[C22; Bf21*E22]; C222=[C22; Bf22*E22];
G211=[G21, -Gf21]; G212=[G21, -Gf22]; G221=[G22, -Gf21]; G222=[G22, -Gf22];
M12=[B12, zeros(2); zeros(2), zeros(2)];
ee1=[1, 0, 0, 0]; ee2=[0, 1, 0, 0]; ee3=[0, 0, 1, 0]; ee4=[0, 0, 0, 1];
x101=0.3; x102=0; x103=0; x104=0; x10=[x101 x102 x103 x104]';
phi1=x10;
x201=0.3; x202=0; x203=0; x204=0; x20=[x201 x202 x203 x204]';
phi2=x20;
h=0.002;
finaltime=15;
%%%%%%%%%%%%%%%%%%%%%%%% initial value of membership function h_i
h11(1:1,1)=abs(0.637*x101);
h12(1:1,1)=1-h11(1:1,1);
ttau1(1:1,1)=0.2*sin(0)-0.1;
tau1(1:1,1)=(fix(ttau1(1:1,1)/h))*h;
h21(1:1,1)=abs(0.637*x201);
h22(1:1,1)=1-h21(1:1,1);
ttau2(1:1,1)=0.2*sin(0)-0.1;
tau2(1:1,1)=(fix(ttau2(1:1,1)/h))*h;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
dx10=(h11(1:1,1)*h11(1:1,1)*A111+h11(1:1,1)*h12(1:1,1)*A112+h12(1:1,1)*h11(1:1,1)*A121+h12(1:1,1)*h12(1:1,1)*A122)*x10+(h11(1:1,1)*h11(1:1,1)*Atau111+h11(1:1,1)*h12(1:1,1)*Atau112+h12(1:1,1)*h11(1:1,1)*Atau121+h12(1:1,1)*h12(1:1,1)*Atau122)*phi1+M21*phi2+(h11(1:1,1)*h11(1:1,1)*C111+h11(1:1,1)*h12(1:1,1)*C112+h12(1:1,1)*h11(1:1,1)*C121+h12(1:1,1)*h12(1:1,1)*C122)*0;
%dx10 is the derivative of x1 at time 0
x1(1:4,1)=dx10*h+x10;
%x1(i) is the value of x1 at step(i)
dx20=(h21(1:1,1)*h21(1:1,1)*A211+h21(1:1,1)*h22(1:1,1)*A212+h22(1:1,1)*h21(1:1,1)*A221+h22(1:1,1)*h22(1:1,1)*A222)*x20+(h21(1:1,1)*h21(1:1,1)*Atau211+h21(1:1,1)*h22(1:1,1)*Atau212+h22(1:1,1)*h21(1:1,1)*Atau221+h22(1:1,1)*h22(1:1,1)*Atau222)*phi2+M12*phi1+(h21(1:1,1)*h21(1:1,1)*C211+h21(1:1,1)*h22(1:1,1)*C212+h22(1:1,1)*h21(1:1,1)*C221+h22(1:1,1)*h22(1:1,1)*C222)*0;
%dx20 is the derivative of x2 at time 0
x2(1:4,1)=dx20*h+x20;
%x2(i) is the value of x2 at step(i)
v1(1:1,1)=0;
v2(1:1,1)=0;
e1(1:2,1)=(h11(1:1,1)*h11(1:1,1)*G111+h11(1:1,1)*h12(1:1,1)*G112+h12(1:1,1)*h11(1:1,1)*G121+h12(1:1,1)*h12(1:1,1)*G122)*x1(1:4,1);
e2(1:2,1)=(h21(1:1,1)*h21(1:1,1)*G211+h21(1:1,1)*h22(1:1,1)*G212+h22(1:1,1)*h21(1:1,1)*G221+h22(1:1,1)*h22(1:1,1)*G222)*x2(1:4,1);
vplus(1:1,1)=h*((v1(1:1,1))^2+(v2(1:1,1))^2);
eplus(1:1,1)=h*((e1(1:2,1))'*e1(1:2,1)+(e2(1:2,1))'*e2(1:2,1));
ev(1:1,1)=eplus(1:1,1)/vplus(1:1,1);
for count=1:finaltime/h
t=count*h;
h11(:,count)=abs(0.637*ee1*x1(:,count));
h12(:,count)=1-h11(:,count);
h21(:,count)=abs(0.637*ee1*x2(:,count));
h22(:,count)=1-h21(:,count);
v1(:,count)=(sin(4*pi*t))*exp(-0.5*t);
v2(:,count)=(sin(4*pi*t))*exp(-0.5*t);
ttau1(:,count)=0.2*sin(t)-0.1;
% tau1(:,count)=(fix(ttau1(:,count)/h)+1)*h;
ttau2(:,count)=0.2*sin(t)-0.1;
% tau2(:,count)=(fix(ttau2(:,count)/h)+1)*h;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if t<=ttau1(:,count)
dx1(:,count)=(h11(:,count)*h11(:,count)*A111+h11(:,count)*h12(:,count)*A112+h12(:,count)*h11(:,count)*A121+h12(:,count)*h12(:,count)*A122)*x1(:,count)+(h11(:,count)*h11(:,count)*Atau111+h11(:,count)*h12(:,count)*Atau112+h12(:,count)*h11(:,count)*Atau121+h12(:,count)*h12(:,count)*Atau122)*phi1+M21*x2(:,count)+(h11(:,count)*h11(:,count)*C111+h11(:,count)*h12(:,count)*C112+h12(:,count)*h11(:,count)*C121+h12(:,count)*h12(:,count)*C122)*v1(:,count);
x1(:,count+1)=dx1(:,count)*h+x1(:,count);
else
dx1(:,count)=(h11(:,count)*h11(:,count)*A111+h11(:,count)*h12(:,count)*A112+h12(:,count)*h11(:,count)*A121+h12(:,count)*h12(:,count)*A122)*x1(:,count)+(h11(:,count)*h11(:,count)*Atau111+h11(:,count)*h12(:,count)*Atau112+h12(:,count)*h11(:,count)*Atau121+h12(:,count)*h12(:,count)*Atau122)*x1(:,count-fix(ttau1(:,count)/h))+M21*x2(:,count)+(h11(:,count)*h11(:,count)*C111+h11(:,count)*h12(:,count)*C112+h12(:,count)*h11(:,count)*C121+h12(:,count)*h12(:,count)*C122)*v1(:,count);
x1(:,count+1)=dx1(:,count)*h+x1(:,count);
end
if t<=ttau2(:,count)
dx2(:,count)=(h21(:,count)*h21(:,count)*A211+h21(:,count)*h22(:,count)*A212+h22(:,count)*h21(:,count)*A221+h22(:,count)*h22(:,count)*A222)*x2(:,count)+(h21(:,count)*h21(:,count)*Atau211+h21(:,count)*h22(:,count)*Atau212+h22(:,count)*h21(:,count)*Atau221+h22(:,count)*h22(:,count)*Atau222)*phi2+M12*x1(:,count)+(h21(:,count)*h21(:,count)*C211+h21(:,count)*h22(:,count)*C212+h22(:,count)*h21(:,count)*C221+h22(:,count)*h22(:,count)*C222)*v2(:,count);
x2(:,count+1)=dx2(:,count)*h+x2(:,count);
else
dx2(:,count)=(h21(:,count)*h21(:,count)*A211+h21(:,count)*h22(:,count)*A212+h22(:,count)*h21(:,count)*A221+h22(:,count)*h22(:,count)*A222)*x2(:,count)+(h21(:,count)*h21(:,count)*Atau211+h21(:,count)*h22(:,count)*Atau212+h22(:,count)*h21(:,count)*Atau221+h22(:,count)*h22(:,count)*Atau222)*x2(:,count-fix(ttau2(:,count)/h))+M12*x1(:,count)+(h21(:,count)*h21(:,count)*C211+h21(:,count)*h22(:,count)*C212+h22(:,count)*h21(:,count)*C221+h22(:,count)*h22(:,count)*C222)*v2(:,count);
x2(:,count+1)=dx2(:,count)*h+x2(:,count);
end
e1(:,count)=(h11(:,count)*h11(:,count)*G111+h11(:,count)*h12(:,count)*G112+h12(:,count)*h11(:,count)*G121+h12(:,count)*h12(:,count)*G122)*x1(:,count);
e2(:,count)=(h21(:,count)*h21(:,count)*G211+h21(:,count)*h22(:,count)*G212+h22(:,count)*h21(:,count)*G221+h22(:,count)*h22(:,count)*G222)*x2(:,count);
vplus(:,count+1)=h*((v1(:,count))^2+(v2(:,count))^2)+vplus(:,count);
eplus(:,count+1)=h*((e1(:,count))'*e1(:,count)+(e2(:,count))'*e2(:,count))+eplus(:,count);
ev(:,count+1)=eplus(:,count+1)/vplus(:,count+1);
end
%%%%%%%%%%%%%plot xi(1),xi(2), e1,e2, in the same fig
hold on
plot([0:h:finaltime],x1(2,)
plot([0:h:finaltime],x1(2,-e1(,'--')
%plot([0:h:finaltime],x2(2,)
%plot([0:h:finaltime],x2(2,-e2(,'--')
%plot([0:h:finaltime],e1()
%plot([0:h:finaltime],e2(,'--')
hold off
%legend('z_1(t)','z_{f1}(t)'))
%legend('z_2(t)','z_{f2}(t)'))
%legend('e_1(t)','e_2(t)'))
%hold on
%plot([0:h:finaltime],ev()
%hold off
%legend('u(t)')
xlabel('Time t')
??? Index exceeds matrix dimensions.
本人是初学者,实在不会,求各位大神帮帮忙 |