clc;clear;close
H1=[-10 0; 0 10/77;-30 0;0 10/19];H2=[1/3;-1/3];H3=[10 0;0 10];
C=[1 0 ; 0 1];
cvx_begin sdp
cvx_solver sedumi
variable W(2,2) symmetric;
variable N(1,4);
variable g11(2,10);variable g12(2,10);variable g21(2,10);variable g22(2,10);
variable g31(2,10);variable g32(2,10);variable g41(2,10);variable g42(2,10);
variable r111(1,1) nonnegative;variable r112(1,1) nonnegative;variable r121(1,1) nonnegative;variable r122(1,1) nonnegative;
variable r211(1,1) nonnegative;variable r212(1,1) nonnegative;variable r221(1,1) nonnegative;variable r222(1,1) nonnegative;
variable r311(1,1) nonnegative;variable r312(1,1) nonnegative;variable r321(1,1) nonnegative;variable r322(1,1) nonnegative;
variable r411(1,1) nonnegative;variable r412(1,1) nonnegative;variable r421(1,1) nonnegative;variable r422(1,1) nonnegative;
variable a111(40,40) semidefinite diagonal;variable a112(40,40) semidefinite diagonal;variable a121(40,40) semidefinite diagonal;variable a122(40,40) semidefinite diagonal;
variable a211(40,40) semidefinite diagonal;variable a212(40,40) semidefinite diagonal;variable a221(40,40) semidefinite diagonal;variable a222(40,40) semidefinite diagonal;
variable a311(40,40) semidefinite diagonal;variable a312(40,40) semidefinite diagonal;variable a321(40,40) semidefinite diagonal;variable a322(40,40) semidefinite diagonal;
variable a411(40,40) semidefinite diagonal;variable a412(40,40) semidefinite diagonal;variable a421(40,40) semidefinite diagonal;variable a422(40,40) semidefinite diagonal;
variable b111(2,2) semidefinite diagonal;variable b112(2,2) semidefinite diagonal;variable b121(2,2) semidefinite diagonal;variable b122(2,2) semidefinite diagonal;
variable b211(2,2) semidefinite diagonal;variable b212(2,2) semidefinite diagonal;variable b221(2,2) semidefinite diagonal;variable b222(2,2) semidefinite diagonal;
variable b311(2,2) semidefinite diagonal;variable b312(2,2) semidefinite diagonal;variable b321(2,2) semidefinite diagonal;variable b322(2,2) semidefinite diagonal;
variable b411(2,2) semidefinite diagonal;variable b412(2,2) semidefinite diagonal;variable b421(2,2) semidefinite diagonal;variable b422(2,2) semidefinite diagonal;
variable v111(2,2) ;variable v112(2,2) ;variable v121(2,2) ;variable v122(2,2) ;
variable v211(2,2) ;variable v212(2,2) ;variable v221(2,2) ;variable v222(2,2) ;
variable v311(2,2) ;variable v312(2,2) ;variable v321(2,2) ;variable v322(2,2) ;
variable v411(2,2) ;variable v412(2,2) ;variable v421(2,2) ;variable v422(2,2) ;
variable X111(2,2) symmetric;variable X112(2,2) symmetric;variable X121(2,2) symmetric;variable X122(2,2) symmetric;
variable X211(2,2) symmetric;variable X212(2,2) symmetric;variable X221(2,2) symmetric;variable X222(2,2) symmetric;
variable X311(2,2) symmetric;variable X312(2,2) symmetric;variable X321(2,2) symmetric;variable X322(2,2) symmetric;
variable X411(2,2) symmetric;variable X412(2,2) symmetric;variable X421(2,2) symmetric;variable X422(2,2) symmetric;
maximize 1e3log_det(W)
subject to
H1W*[-1;1]<=ones(4,1);H1W[1;-1]<=ones(4,1);
H1W[-1;-1]<=ones(4,1);H1W[1;1]<=ones(4,1);
H2Nkron([1;0],[-1;1])<=ones(2,1);H2Nkron([1;0],[1;-1])<=ones(2,1);
H2Nkron([1;0],[-1;-1])<=ones(2,1);H2Nkron([1;0],[1;1])<=ones(2,1);
H2Nkron([0;1],[-1;1])<=ones(2,1);H2Nkron([0;1],[1;-1])<=ones(2,1);
H2Nkron([0;1],[-1;-1])<=ones(2,1);H2Nkron([0;1],[1;1])<=ones(2,1);
e1=[1;0];e2=[0;1];
x1=[-0.0075;0.6418];x2=[0.0596;0.0920];x3=[0.0708;1.1201];x4=[0.2187;1.1212];x5=[0.3698;1.7478];x6=[0.6163;1.3712];x7=[0.8469;1.8387];x8=[1.1548;1.6224];x9=[1.4399;1.3763];x10=[1.7696;1.1218];
x11=[2.0894;1.0531];x12=[2.4144;1.0533];x13=[2.8058;1.5208];x14=[3.2876;1.1072];x15=[3.8131;0.8257];x16=[4.3468;0.3891];x17=[4.9057;0.9454];x18=[5.5151;0.5132];x19=[6.2247;0.3929];x20=[6.9148;-0.2357];
x21=[7.6314;0.2077];
X1=[0.0596 0.0708 0.2187 0.3698 0.6163 0.8469 1.1548 1.4399 1.7696 2.0894 2.4144 2.8058 3.2876 3.8131 4.3468 4.9057 5.5151 6.2247 6.9148 7.6314;
0.0920 1.1201 1.1212 1.7478 1.3712 1.8387 1.6224 1.3763 1.1218 1.0531 1.0533 1.5208 1.1072 0.8257 0.3891 0.9454 0.5132 0.3929 -0.2357 0.2077];
p1=[0.1629;0.1265];p2=[0.1915;0.1914];p3=[0.0844;0.1311];p4=[0.1357;0.1311];p5=[0.0554;0.1390];p6=[0.0877;0.0374];p7=[0.1419;0.1310];p8=[0.1919;0.1503];p9=[0.1782;0.0299];p10=[0.1629;0.0393];
p11=[0.0703;0.1834];p12=[0.0761;0.1062];p13=[0.1138;0.0324];p14=[0.0331;0.1378];p15=[0.0458;0.1077];p16=[0.0213;0.1635];p17=[0.0520;0.0364];p18=[0.1739;0.1706];p19=[0.0804;0.0368];p20=[0.1805;0.0675];
X2=[kron(p1,x1) kron(p2,x2) kron(p3,x3) kron(p4,x4) kron(p5,x5) kron(p6,x6) kron(p7,x7) kron(p8,x8) kron(p9,x9) kron(p10,x10) kron(p11,x11) kron(p12,x12) kron(p13,x13) kron(p14,x14) kron(p15,x15) kron(p16,x16) kron(p17,x17) kron(p18,x18) kron(p19,x19) kron(p20,x20);
6.3355 -6.2308 10.0777 -1.2522 4.9588 -5.8299 3.1388 -4.1491 -4.2380 -4.0197 -1.9658 -1.1202 3.4371 -5.8565 -4.0787 -5.3563 5.1768 -5.2463 -1.7697 -6.6895];
d=[H3*x2;H3*x3;H3*x4;H3*x5;H3*x6;H3*x7;H3*x8;H3*x9;H3*x10;H3*x11;H3*x12;H3*x13;H3*x14;H3*x15;H3*x16;H3*x17;H3*x18;H3*x19;H3*x20;H3*x21];
Z=kron(X2',H3);
g11==kron(([kron(eye(2),W);N]*kron([0;1],[1;-1]))',eye(2));
g21==kron(([kron(eye(2),W);N]*kron([0;1],[-1;1]))',eye(2));
g31==kron(([kron(eye(2),W);N]*kron([0;1],[1;1]))',eye(2));
g41==kron(([kron(eye(2),W);N]*kron([0;1],[-1;-1]))',eye(2));
g12==kron(([kron(eye(2),W);N]*kron([1;0],[1;-1]))',eye(2));
g22==kron(([kron(eye(2),W);N]*kron([1;0],[-1;1]))',eye(2));
g32==kron(([kron(eye(2),W);N]*kron([1;0],[1;1]))',eye(2));
g42==kron(([kron(eye(2),W);N]*kron([1;0],[-1;-1]))',eye(2));
% g11==kron(([kron(eye(2),W);N]*kron([1;0],[1;-1]))‘,eye(2));
% g12==kron(([kron(eye(2),W);N]*kron([1;0],[1;1]))’,eye(2));
% g21==kron(([kron(eye(2),W);N]*kron([1;0],[-1;1]))‘,eye(2));
% g22==kron(([kron(eye(2),W);N]*kron([0;1],[-1;-1]))’,eye(2));
% g31==kron(([kron(eye(2),W);N]*kron([0;1],[1;-1]))‘,eye(2));
% g32==kron(([kron(eye(2),W);N]*kron([0;1],[1;1]))’,eye(2));
% g41==kron(([kron(eye(2),W);N]*kron([0;1],[-1;1]))‘,eye(2));
% g42==kron(([kron(eye(2),W);N]*kron([0;1],[-1;-1]))’,eye(2));
[W'+W-X111 (r111)*C'*e1;(r111)*e1'*C r111]==semidefinite(3);
[W'+W-X112 (r112)*C'*e2;(r112)*e2'*C r112]==semidefinite(3);
[W'+W-X121 (r121)*C'*e1;(r121)*e1'*C r121]==semidefinite(3);
[W'+W-X122 (r122)*C'*e2;(r122)*e2'*C r122]==semidefinite(3);
[W'+W-X211 (r211)*C'*e1;(r211)*e1'*C r211]==semidefinite(3);
[W'+W-X212 (r212)*C'*e2;(r212)*e2'*C r212]==semidefinite(3);
[W'+W-X221 (r221)*C'*e1;(r221)*e1'*C r221]==semidefinite(3);
[W'+W-X222 (r222)*C'*e2;(r222)*e2'*C r222]==semidefinite(3);
[W'+W-X311 (r311)*C'*e1;(r311)*e1'*C r311]==semidefinite(3);
[W'+W-X312 (r312)*C'*e2;(r312)*e2'*C r312]==semidefinite(3);
[W'+W-X321 (r321)*C'*e1;(r321)*e1'*C r321]==semidefinite(3);
[W'+W-X322 (r322)*C'*e2;(r322)*e2'*C r322]==semidefinite(3);
[W'+W-X411 (r411)*C'*e1;(r411)*e1'*C r411]==semidefinite(3);
[W'+W-X412 (r412)*C'*e2;(r412)*e2'*C r412]==semidefinite(3);
[W'+W-X421 (r421)*C'*e1;(r421)*e1'*C r421]==semidefinite(3);
[W'+W-X422 (r422)*C'*e2;(r422)*e2'*C r422]==semidefinite(3);
[r111 -d'*(a111)*Z zeros(1,2) zeros(1,2) zeros(1,2);
-Z'*(a111)*d Z'*(a111)*Z zeros(10,2) (g11)' zeros(10,2);
zeros(2,1) zeros(2,10) H3'*(b111)*H3 eye(2) zeros(2,2);
zeros(2,1) g11 eye(2) (v111)+(v111)' (v111)';
zeros(2,1) zeros(2,10) zeros(2,2) v111 X111]==semidefinite(17);
[r112 -d'*(a112)*Z zeros(1,2) zeros(1,2) zeros(1,2);
-Z'*(a112)*d Z'*(a112)*Z zeros(10,2) (g11)' zeros(10,2);
zeros(2,1) zeros(2,10) H3'*(b112)*H3 eye(2) zeros(2,2);
zeros(2,1) g11 eye(2) (v112)+(v112)' (v112)';
zeros(2,1) zeros(2,10) zeros(2,2) v112 X112]==semidefinite(17);
[r121 -d'*(a121)*Z zeros(1,2) zeros(1,2) zeros(1,2);
-Z'*(a121)*d Z'*(a121)*Z zeros(10,2) (g12)' zeros(10,2);
zeros(2,1) zeros(2,10) H3'*(b121)*H3 eye(2) zeros(2,2);
zeros(2,1) g12 eye(2) (v121)+(v121)' (v121)';
zeros(2,1) zeros(2,10) zeros(2,2) v121 X121]==semidefinite(17);
[r122 -d'*(a122)*Z zeros(1,2) zeros(1,2) zeros(1,2);
-Z'*(a122)*d Z'*(a122)*Z zeros(10,2) (g12)' zeros(10,2);
zeros(2,1) zeros(2,10) H3'*(b122)*H3 eye(2) zeros(2,2);
zeros(2,1) g12 eye(2) (v122)+(v122)' (v122)';
zeros(2,1) zeros(2,10) zeros(2,2) v122 X122]==semidefinite(17);
[r211 -d'*(a211)*Z zeros(1,2) zeros(1,2) zeros(1,2);
-Z'*(a211)*d Z'*(a211)*Z zeros(10,2) (g21)' zeros(10,2);
zeros(2,1) zeros(2,10) H3'*(b211)*H3 eye(2) zeros(2,2);
zeros(2,1) g21 eye(2) (v211)+(v211)' (v211)';
zeros(2,1) zeros(2,10) zeros(2,2) v211 X211]==semidefinite(17);
[r212 -d'*(a212)*Z zeros(1,2) zeros(1,2) zeros(1,2);
-Z'*(a212)*d Z'*(a212)*Z zeros(10,2) (g21)' zeros(10,2);
zeros(2,1) zeros(2,10) H3'*(b112)*H3 eye(2) zeros(2,2);
zeros(2,1) g21 eye(2) (v212)+(v212)' (v212)';
zeros(2,1) zeros(2,10) zeros(2,2) v212 X212]==semidefinite(17);
[r221 -d'*(a221)*Z zeros(1,2) zeros(1,2) zeros(1,2);
-Z'*(a221)*d Z'*(a221)*Z zeros(10,2) (g22)' zeros(10,2);
zeros(2,1) zeros(2,10) H3'*(b221)*H3 eye(2) zeros(2,2);
zeros(2,1) g22 eye(2) (v221)+(v221)' (v221)';
zeros(2,1) zeros(2,10) zeros(2,2) v221 X221]==semidefinite(17);
[r222 -d'*(a222)*Z zeros(1,2) zeros(1,2) zeros(1,2);
-Z'*(a222)*d Z'*(a222)*Z zeros(10,2) (g22)' zeros(10,2);
zeros(2,1) zeros(2,10) H3'*(b222)*H3 eye(2) zeros(2,2);
zeros(2,1) g22 eye(2) (v222)+(v222)' (v222)';
zeros(2,1) zeros(2,10) zeros(2,2) v222 X222]==semidefinite(17);
[r311 -d'*(a311)*Z zeros(1,2) zeros(1,2) zeros(1,2);
-Z'*(a311)*d Z'*(a311)*Z zeros(10,2) (g31)' zeros(10,2);
zeros(2,1) zeros(2,10) H3'*(b311)*H3 eye(2) zeros(2,2);
zeros(2,1) g31 eye(2) (v311)+(v311)' (v311)';
zeros(2,1) zeros(2,10) zeros(2,2) v311 X311]==semidefinite(17);
[r312 -d'*(a312)*Z zeros(1,2) zeros(1,2) zeros(1,2);
-Z'*(a312)*d Z'*(a312)*Z zeros(10,2) (g31)' zeros(10,2);
zeros(2,1) zeros(2,10) H3'*(b312)*H3 eye(2) zeros(2,2);
zeros(2,1) g31 eye(2) (v312)+(v312)' (v312)';
zeros(2,1) zeros(2,10) zeros(2,2) v312 X312]==semidefinite(17);
[r321 -d'*(a321)*Z zeros(1,2) zeros(1,2) zeros(1,2);
-Z'*(a321)*d Z'*(a321)*Z zeros(10,2) (g32)' zeros(10,2);
zeros(2,1) zeros(2,10) H3'*(b321)*H3 eye(2) zeros(2,2);
zeros(2,1) g32 eye(2) (v321)+(v321)' (v321)';
zeros(2,1) zeros(2,10) zeros(2,2) v321 X321]==semidefinite(17);
[r322 -d'*(a322)*Z zeros(1,2) zeros(1,2) zeros(1,2);
-Z'*(a322)*d Z'*(a322)*Z zeros(10,2) (g32)' zeros(10,2);
zeros(2,1) zeros(2,10) H3'*(b322)*H3 eye(2) zeros(2,2);
zeros(2,1) g32 eye(2) (v322)+(v322)' (v322)';
zeros(2,1) zeros(2,10) zeros(2,2) v322 X322]==semidefinite(17);
[r411 -d'*(a411)*Z zeros(1,2) zeros(1,2) zeros(1,2);
-Z'*(a411)*d Z'*(a411)*Z zeros(10,2) (g41)' zeros(10,2);
zeros(2,1) zeros(2,10) H3'*(b411)*H3 eye(2) zeros(2,2);
zeros(2,1) g41 eye(2) (v411)+(v411)' (v411)';
zeros(2,1) zeros(2,10) zeros(2,2) v411 X411]==semidefinite(17);
[r412 -d'*(a412)*Z zeros(1,2) zeros(1,2) zeros(1,2);
-Z'*(a412)*d Z'*(a412)*Z zeros(10,2) (g41)' zeros(10,2);
zeros(2,1) zeros(2,10) H3'*(b412)*H3 eye(2) zeros(2,2);
zeros(2,1) g41 eye(2) (v112)+(v112)' (v112)';
zeros(2,1) zeros(2,10) zeros(2,2) v412 X412]==semidefinite(17);
[r421 -d'*(a421)*Z zeros(1,2) zeros(1,2) zeros(1,2);
-Z'*(a421)*d Z'*(a421)*Z zeros(10,2) (g42)' zeros(10,2);
zeros(2,1) zeros(2,10) H3'*(b421)*H3 eye(2) zeros(2,2);
zeros(2,1) g42 eye(2) (v421)+(v421)' (v421)';
zeros(2,1) zeros(2,10) zeros(2,2) v421 X421]==semidefinite(17);
[r422 -d'*(a422)*Z zeros(1,2) zeros(1,2) zeros(1,2);
-Z'*(a422)*d Z'*(a422)*Z zeros(10,2) (g42)' zeros(10,2);
zeros(2,1) zeros(2,10) H3'*(b422)*H3 eye(2) zeros(2,2);
zeros(2,1) g42 eye(2) (v422)+(v422)' (v422)';
zeros(2,1) zeros(2,10) zeros(2,2) v422 X422]==semidefinite(17);
cvx_end
cvx_optval