

 clear
clc
pkg load control
a01 = [          0                  0                  0   0.99857378005981;
                 0                  0   1.00000000000000  -0.00318221934140;
                 0                  0 -11.57049560546880  -2.54463768005371;
                 0                  0   0.43935656547546  -1.99818229675293;
                 0                  0  -2.04089546203613  -0.45899915695190;
-32.10360717773440                  0  -0.50335502624512   2.29785919189453;
  0.10216116905212  32.05783081054690  -2.34721755981445  -0.50361156463623;
 -1.91097259521484   1.71382904052734  -0.00400543212891  -0.05741119384766];

a02 = [0.05338427424431             0                  0                  0;
  0.05952465534210                  0                  0                  0;
 -0.06360262632370   0.10678052902222  -0.09491866827011   0.00710757449269;
                 0   0.01665188372135   0.01846204698086  -0.00118747074157;
 -0.73502779006958   0.01925575733185  -0.00459562242031   0.00212036073208;
                 0  -0.02121581137180  -0.02116791903973   0.01581159234047;
  0.83494758605957   0.02122657001019  -0.03787973523140   0.00035400385968;
                 0   0.01398963481188  -0.00090675335377  -0.29051351547241];

a0=[a01 a02];

b0=[              0                  0                  0                  0;
                  0                  0                  0                  0;
   0.12433505058289   0.08278584480286  -2.75247764587402  -0.01788876950741;
  -0.03635892271996   0.47509527206421   0.01429074257612                  0;
   0.30449151992798   0.01495801657438  -0.49651837348938  -0.20674192905426;
   0.28773546218872  -0.54450607299805  -0.01637935638428                  0;
  -0.01907348632812   0.01636743545532  -0.54453611373901   0.23484230041504;
  -4.82063293457031  -0.00038146972656                  0                 0];

c0 = [ 0        0         0         0         0    0.0595   0.05329  -0.9968;
     1.0        0         0         0         0         0         0        0;
       0      1.0         0         0         0         0         0        0;
       0        0         0  -0.05348       1.0         0         0        0;
       0        0       1.0         0         0         0         0        0;
       0        0         0       1.0         0         0         0       0];

d0 = zeros(6,4);
G=ss(a0,b0,c0,d0);
%----------------------------------------------------------------------------
disp('*******Constructing Weights')

%  aw1

n11=0.5*[1 12];
d11=[1 0.012];

n12=0.89*[1 2.81];
d12=[1 0.005];

n13=0.89*[1 2.81];
d13=[1 0.005];

n14=0.5*[1 10];
d14=[1 0.01];

n15=2*[1 0];
d15=[1 8.5 18];

n16=2*[1 0];
d16=[1 8.5 18];

[aw11,bw11,cw11,dw11]=ssdata(tf(n11,d11));
[aw12,bw12,cw12,dw12]=ssdata(tf(n12,d12));
[aw13,bw13,cw13,dw13]=ssdata(tf(n13,d13));
[aw14,bw14,cw14,dw14]=ssdata(tf(n14,d14));
[aw15,bw15,cw15,dw15]=ssdata(tf(n15,d15));
[aw16,bw16,cw16,dw16]=ssdata(tf(n16,d16));

aw1=blkdiag(aw11,aw12,aw13,aw14,aw15,aw16);
bw1=blkdiag(bw11,bw12,bw13,bw14,bw15,bw16);
cw1=blkdiag(cw11,cw12,cw13,cw14,cw15,cw16);
dw1=blkdiag(dw11,dw12,dw13,dw14,dw15,dw16);

W1=ss(aw1,bw1,cw1,dw1);

n21=0.5*[1 0.0001];
d21=[1 10];

n22=0.5*[1 0.0001];
d22=[1 10];

n23=0.5*[1 0.0001];
d23=[1 10];

n24=0.5*[1 0.0001];
d24=[1 10];

[aw21,bw21,cw21,dw21]=ssdata(tf(n21,d21));
[aw22,bw22,cw22,dw22]=ssdata(tf(n22,d22));
[aw23,bw23,cw23,dw23]=ssdata(tf(n23,d23));
[aw24,bw24,cw24,dw24]=ssdata(tf(n24,d24));

aw2=blkdiag(aw21,aw22,aw23,aw24);
bw2=blkdiag(bw21,bw22,bw23,bw24);
cw2=blkdiag(cw21,cw22,cw23,cw24);
dw2=blkdiag(dw21,dw22,dw23,dw24);

W2=ss(aw2,bw2,cw2,dw2);


W3=blkdiag(1,1,1,1,0.1,0.1);

%----------------------------------------------------------------------------
% Output Scaling
scaleyue=blkdiag(0.1,5,2,2,2,5);
c0sc=scaleyue*c0;
G1=G;
G1.c=c0sc;



disp('Forming Standard Plant Configuration')

P1=horzcat(W1*W3,-W1*G1);
P2=horzcat(zeros(4,6),W2);
P3=horzcat(W3,-G1);
P=vertcat(P1,P2,P3);
p=minreal(P);

%----------------------------------------------------------------------------
disp('*******H-infinity solving ')
 
[k,CL,gam]=hinfsyn(p,6,4);
