# Talk:Beginning with CVX

(Difference between revisions)
 Revision as of 10:02, 5 February 2009 (edit)← Previous diff Current revision (01:00, 10 February 2009) (edit) (undo) (8 intermediate revisions not shown.) Line 6: Line 6: Thanks a lot for all the ideas, they all are greats. Thanks a lot for all the ideas, they all are greats. - I don't know how to initialice Epsilon1 and Epsilon2. At the article don't put anything. + The code still not working. I think I’m making thinks wrong (sure). I have a dude. - I put off the while structure. + The new code could be: - Thanks a lot again. +
+                                                         %0)Initialization
+                                                         clear all;

-                                                            Here is the new code:                                                                     +                                                         %cvx_setup
-                                                                                                                                                      +
-
%0)Initialization                                                                    +
-                                                            clear all;                                                                                +
n=2; m=1;                                                                                                                                           n=2; m=1;

Line 30:                                                                                                                                               Line 29:
lamda_W=min(eig(full(W)))                                                                                                                           lamda_W=min(eig(full(W)))
lamda_H=max(eig(H))                                                                                                                                 lamda_H=max(eig(H))
-                                                                                                                                                      +                                                         Epsilon1=1e-6;
-                                                            Epsilon1=11;                                                                              +                                                         Epsilon2=1e-6;
-                                                            Epsilon2=0.1;                                                                             +                                                         %3)3
-                                                                                                                                                      +                                                         [v_W,D] = eig( full ( W ) )
-                                                            if(lamda_W>=Epsilon1)                                                                     +                                                         [v_H,D] = eig( full ( H ) )
-                                                            if(lamda_H<=-Epsilon2)     para=1                                                         +
-                                                            else para = 0                                                                             +
-                                                            end                                                                                       +
-                                                            else para =0                                                                              +
-                                                            end                                                                                       +
-                                                                                                                                                      +
-                                                            %while para==0                                                                            +
-                                                            %3)3                                                                                      +
-                                                            [v_W,D] = eig( full ( W ) )                                                               +
-                                                            [v_H,D] = eig( full ( H ) )                                                               +

-                                                            v_W_1 = v_W( : , 1 ) / norm ( v_W ( : , 1 ) ) ;
-                                                            v_W_2 = v_W( : , 2 ) / norm ( v_W ( : , 2 ) ) ;
-                                                            v_W_3 = v_W( : , 3 ) / norm ( v_W ( : , 3 ) ) ;
-                                                            v_W_4 = v_W( : , 4 ) / norm ( v_W ( : , 4 ) ) ;
-
-                                                            v_H_1 = v_H( : , 1 ) / norm ( v_H ( : , 1 ) ) ;
-                                                            v_H_2 = v_H( : , 2 ) / norm ( v_H ( : , 2 ) ) ;
-                                                            v_H_3 = v_H( : , 3 ) / norm ( v_H ( : , 3 ) ) ;
-                                                            v_H_4 = v_H( : , 4 ) / norm ( v_H ( : , 4 ) ) ;
-
-                                                            %4a)4a
-                                                            if ( Epsilon1 - lamda_W )>(lamda_H+Epsilon2)
-                                                            Caso=1 %For know where am I
-
cvx_begin                                                                                                                                           cvx_begin
variables p1 p2 W(4,4) R(2,4)                                                                                                                       variables p1 p2 W(4,4) R(2,4)
+                                                         if ( Epsilon1 - lamda_W )>(lamda_H+Epsilon2)    CK=v_W'*W*v_W - Epsilon1*eye(2*n) ;
+                                                         else CK=-Epsilon2*eye(2*n) - v_H'*H*v_H ;
+                                                         end
+
+                                                         minimize (p1+p2)

-                                                            minimize (p1+p2)                                                                          +                                                         subject to
-                                                                                                                                                      +
-                                                            subject to                                                                                +

-                                                            W(1,1)<=p1                                                                                +                                                         W(1,1)<=p1
-                                                            W(2,2)<=p1                                                                                +                                                         W(2,2)<=p1
-                                                            W(1,1)>=Epsilon1                                                                          +                                                         W(1,1)>=Epsilon1
-                                                            W(2,2)>=Epsilon1                                                                          +                                                         W(2,2)>=Epsilon1
-                                                            W(3,3)==W(1,1)                                                                            +                                                         W(3,3)==W(1,1)
-                                                            W(4,4)==W(2,2)                                                                            +                                                         W(4,4)==W(2,2)

-                                                            R(1,1)>=-p2                                                                               +                                                         R(1,1)>=-p2
-                                                            R(1,1)<=p2                                                                                +                                                         R(1,1)<=p2
-                                                            R(2,3)==R(1,1)                                                                            +                                                         R(2,3)==R(1,1)
-                                                            R(1,2)>=-p2                                                                               +                                                         R(1,2)>=-p2
-                                                            R(1,2)<=p2                                                                                +                                                         R(1,2)<=p2
-                                                            R(2,4)==R(1,2)                                                                            +                                                         R(2,4)==R(1,2)

-                                                            H=W*A_a'+A_a*W-B_a*R-R'*B_a'                                                              +                                                         CK  == semidefinite(2*n);
-                                                                                                                                                      +
-                                                            v_W'*W*v_W - Epsilon1*eye(2*n) == semidefinite(2*n);                                      +

cvx_end                                                                                                                                             cvx_end

-                                                            else %4b)4b                                                                               +                                                         lamda_W = min ( eig ( full ( W ) ) )
-                                                                                                                                                      +                                                         lamda_H = max ( eig ( full ( H ) ) )
-                                                            Caso = 2                                                                                  +
-                                                            cvx_begin                                                                                 +
-                                                                                                                                                      +
-                                                            variables p1 p2 W(4,4) R(2,4)                                                             +
-                                                                                                                                                      +
-                                                            minimize (p1+p2)                                                                          +
-                                                                                                                                                      +
-                                                            subject to                                                                                +
-                                                                                                                                                      +
-                                                            W(1,1)>=Epsilon1                                                                          +
-                                                            W(2,2)>=Epsilon1                                                                          +
-                                                            W(1,1)<=p1                                                                                +
-                                                            W(2,2)<=p1                                                                                +
-                                                            W(3,3)==W(1,1)                                                                            +
-                                                            W(4,4)==W(2,2)                                                                            +
-                                                                                                                                                      +
-                                                            R(1,1)>=-p2                                                                               +
-                                                            R(1,1)<=p2                                                                                +
-                                                            R(2,3)==R(1,1)                                                                            +
-                                                            R(1,2)>=-p2                                                                               +
-                                                            R(1,2)<=p2                                                                                +
-                                                            R(2,4)==R(1,2)                                                                            +
-                                                                                                                                                      +
-                                                            H=W*A_a'+A_a*W-B_a*R-R'*B_a'                                                              +
-                                                                                                                                                      +
-                                                            Epsilon2*eye(2*n) + v_H'*H*v_H == -semidefinite(2*n);                                     +
-                                                                                                                                                      +
-                                                            cvx_end                                                                                   +
-                                                            end                                                                                       +
-                                                                                                                                                      +

R                                                                                                                                                   R
W=full(W)                                                                                                                                           W=full(W)
K=R/W                                                                                                                                               K=R/W
+

## Current revision

```lamda_W=eig(full(W))
```

Thanks a lot for all the ideas, they all are greats.

The code still not working. I think I’m making thinks wrong (sure). I have a dude.

The new code could be:

```%0)Initialization
clear all;

%cvx_setup
n=2; m=1;

A_a=3*eye(2*n,2*n)
B_a=4*eye(2*n,2*m)

%1)1
W=eye(4)
R=(zeros(2,4))

%2)2
H=W*A_a'+A_a*W-B_a*R-R'*B_a'

lamda_W=min(eig(full(W)))
lamda_H=max(eig(H))
Epsilon1=1e-6;
Epsilon2=1e-6;
%3)3
[v_W,D] = eig( full ( W ) )
[v_H,D] = eig( full ( H ) )

cvx_begin
variables p1 p2 W(4,4) R(2,4)
if ( Epsilon1 - lamda_W )>(lamda_H+Epsilon2)    CK=v_W'*W*v_W - Epsilon1*eye(2*n) ;
else CK=-Epsilon2*eye(2*n) - v_H'*H*v_H ;
end

minimize (p1+p2)

subject to

W(1,1)<=p1
W(2,2)<=p1
W(1,1)>=Epsilon1
W(2,2)>=Epsilon1
W(3,3)==W(1,1)
W(4,4)==W(2,2)

R(1,1)>=-p2
R(1,1)<=p2
R(2,3)==R(1,1)
R(1,2)>=-p2
R(1,2)<=p2
R(2,4)==R(1,2)

CK  == semidefinite(2*n);

cvx_end

lamda_W = min ( eig ( full ( W ) ) )
lamda_H = max ( eig ( full ( H ) ) )

R
W=full(W)
K=R/W

```