Talk:Beginning with CVX
From Wikimization
(Difference between revisions)
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. | ||
- | Kwokwah That was my first idea (could be great if it works), but isn't possible to do one "if" inside the "cvx_begin - cvx_end" Because it isn't a convex problem. | ||
- | |||
- | Michael Grant explains to me (I'm going to copy it's explanation): | ||
- | |||
- | "Do make sure you understand that if-then statements are typically not | ||
- | possible in CVX. In general such constraints will not be convex, and | ||
- | CVX does not handle nonconvex problems. CVX requires not only that | ||
- | problems be convex, but they must be constructed according to the very | ||
- | specific rules outlined in the user guide. If those rules are not | ||
- | satisfied then CVX rejects the model." | ||
- | |||
- | I think I'm wrong with this code, I would like to put the "if" with the another constraits, inside the cxv_begin, but the CVX don't let me doing it. Some ideas? | ||
I think I’m making thinks wrong. I have a dude. | I think I’m making thinks wrong. I have a dude. | ||
The new code could be: | The new code could be: | ||
- | <pre> | ||
- | 1º I calculate some variables, | ||
- | |||
- | 2º with one if (with depends to variables point 1º) I select one linear constrint depending | ||
- | value of variables in 1º and I make all the: minimize…subjet to with apropiate constraints, convex | ||
- | and the one linear, | ||
- | |||
- | if | ||
- | cvx_begin | ||
- | ... | ||
- | cvx_end | ||
- | else | ||
- | cvx_begin | ||
- | ... | ||
- | cvx_end | ||
- | end | ||
- | |||
- | 3ºIf there is not solution STOP, if there is, go to 1º, | ||
- | </pre> | ||
- | I’ve tried making this, I make: 1º, 2, 3º; return to 1º,2º, 3º And here the CVX says that there is not solution, that’s the reason for trying to keep inside the if – else. | ||
- | |||
- | My dude is, why CVX says there is not solution, it could be because the iteration (making steps 1-2-3) before is the correct. For explain (I know my English isn’t the best, and it’s hard for me to explain and for you to read) | ||
- | <pre> | ||
- | One iteracion (steps 1, 2, 3) | ||
- | |||
- | All well | ||
- | |||
- | Save data = DATA1 | ||
- | |||
- | One iteracion (steps 1, 2, 3) | ||
- | |||
- | All well | ||
- | |||
- | Save data = DATA2 | ||
- | |||
- | One iteracion (steps 1, 2, 3) | ||
- | |||
- | Wrong, no solution | ||
- | |||
- | Correct data = DATA2 | ||
- | </pre> | ||
- | What do you think? Any idea? | ||
- | |||
- | Thanks a lot for all, again. | ||
- | |||
- | ----------------------------------------------------------------------- | ||
- | |||
- | I don't know how to initialice Epsilon1 and Epsilon2. I'm trying different values. | ||
- | |||
- | Thanks a lot again. | ||
- | |||
- | Here is the new code: | ||
- | |||
<pre> | <pre> | ||
%0)Initialization | %0)Initialization | ||
clear all; | clear all; | ||
+ | |||
+ | cvx_setup | ||
n=2; m=1; | n=2; m=1; | ||
A_a=3*eye(2*n,2*n) | A_a=3*eye(2*n,2*n) | ||
- | B_a=4*eye(2*n,2*m) | + | B_a=4*eye(2*n,2*m) |
%1)1 | %1)1 | ||
Line 93: | Line 30: | ||
lamda_H=max(eig(H)) | lamda_H=max(eig(H)) | ||
- | Epsilon1= | + | DOK.W=W; |
- | Epsilon2= | + | DOK.R=R |
+ | DOK.lW=lamda_W; | ||
+ | DOK.lH=lamda_H; | ||
+ | |||
+ | Epsilon1=1e-6; | ||
+ | Epsilon2=1e-6; | ||
if(lamda_W>=Epsilon1) | if(lamda_W>=Epsilon1) | ||
- | + | if(lamda_H<=-Epsilon2) para=1 | |
- | + | else para = 0 | |
- | + | end | |
else para =0 | else para =0 | ||
end | end | ||
- | + | while para==0 | |
- | %3)3 | + | %3)3 |
- | [v_W,D] = eig(full(W)) | + | [v_W,D] = eig( full ( W ) ) |
- | [v_H,D] = eig(full(H)) | + | [v_H,D] = eig( full ( H ) ) |
+ | |||
+ | %4a)4a | ||
+ | if ( Epsilon1 - lamda_W )>(lamda_H+Epsilon2) | ||
+ | Caso=1 %For know where am I | ||
- | + | DOK.W=W; | |
- | + | DOK.R=R | |
- | + | DOK.lW=lamda_W; | |
- | + | DOK.lH=lamda_H; | |
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | cvx_begin | |
- | + | variables p1 p2 W(4,4) R(2,4) | |
- | + | ||
- | + | 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) | ||
+ | |||
+ | H=W*A_a'+A_a*W-B_a*R-R'*B_a' | ||
+ | |||
+ | v_W'*W*v_W - Epsilon1*eye(2*n) == semidefinite(2*n); | ||
- | H=W*A_a'+A_a*W-B_a*R-R'*B_a'; | ||
- | if (Epsilon1 - lamda_W) > (lamda_H + Epsilon2) | ||
- | v_W'*W*v_W - Epsilon1*eye(2*n) == semidefinite(2*n); | ||
- | else | ||
- | Epsilon2*eye(2*n) + v_H'*H*v_H == -semidefinite(2*n); | ||
- | end | ||
cvx_end | cvx_end | ||
+ | |||
+ | else %4b)4b | ||
+ | |||
+ | Caso = 2 | ||
+ | DOK.W=W; | ||
+ | DOK.R=R | ||
+ | DOK.lW=lamda_W; | ||
+ | DOK.lH=lamda_H; | ||
+ | |||
+ | 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 | ||
+ | |||
+ | lamda_W = min ( eig ( full ( W ) ) ) | ||
+ | lamda_H = max ( eig ( full ( H ) ) ) | ||
+ | |||
+ | end | ||
R | R | ||
W=full(W) | W=full(W) | ||
- | K=R/W | + | K=R/W</pre> |
- | </pre> | + |
Revision as of 07:51, 9 February 2009
lamda_W=eig(full(W))
Thanks a lot for all the ideas, they all are greats.
I think I’m making thinks wrong. 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)) DOK.W=W; DOK.R=R DOK.lW=lamda_W; DOK.lH=lamda_H; Epsilon1=1e-6; Epsilon2=1e-6; if(lamda_W>=Epsilon1) 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 ) ) %4a)4a if ( Epsilon1 - lamda_W )>(lamda_H+Epsilon2) Caso=1 %For know where am I DOK.W=W; DOK.R=R DOK.lW=lamda_W; DOK.lH=lamda_H; cvx_begin variables p1 p2 W(4,4) R(2,4) 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) H=W*A_a'+A_a*W-B_a*R-R'*B_a' v_W'*W*v_W - Epsilon1*eye(2*n) == semidefinite(2*n); cvx_end else %4b)4b Caso = 2 DOK.W=W; DOK.R=R DOK.lW=lamda_W; DOK.lH=lamda_H; 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 lamda_W = min ( eig ( full ( W ) ) ) lamda_H = max ( eig ( full ( H ) ) ) end R W=full(W) K=R/W