very simple blkvar question

49 views
Skip to first unread message

Jhlaks

unread,
Apr 3, 2013, 11:53:26 AM4/3/13
to yal...@googlegroups.com
Is it possible to define a variable which is not symmetric using the blkvar command?  For example, if certain sections of a variable are constrained to be zero as in:

%want a non-symmetric variable that has (1,2) corner constrained to be 0:
% non_sym_var=[ A  0
%                        B1 B2];
%
A=sdpvar(1);
B1=sdpvar(1);
B2=sdpvar(1);

non_sym_var=blkvar;
non_sym_var(1,1)=A;
non_sym_var(2,1)=B1;
non_sym_var(2,2)=B2;
non_sym_var(1,2)=0;

This would be a short cut to get around using equality constraints to force non_sym_var(1,2)=0 as in:

non_sym_var=sdpvar(2,2,'full');
non_sym_constr=[ [1 0]*non_sym_var*[0;1]==0];


Thanks!
-Jason

Johan Löfberg

unread,
Apr 3, 2013, 12:42:14 PM4/3/13
to yal...@googlegroups.com
Why don't you simply add the constraint

non_sym_constr = non_sym_var(1,2) == 0

or after defining the variable, just zero out the element

non_sym_var=sdpvar(2,2,'full');
non_sym_var
(1,2)=0;


BTW, using blkvar typically makes code hard to follow. I never use it and recommend you to use as much standard MATLAB syntax as possible to make your code easily read by non-YALMIP users.

Jhlaks

unread,
Apr 3, 2013, 1:38:17 PM4/3/13
to yal...@googlegroups.com
Thanks, Johan!  I did not realize you could add a constraint to a blkvar so easily.  However, when the blkvar becomes a variable in a semidefinite program, will the constraint:


non_sym_constr = non_sym_var(1,2) == 0

then also force

non_sym_constr = non_sym_var(2,1) == 0

?  At present, to make sure that the variable has the required block structure, I am solving the semidef program using something like

non_sym_var=sdpvar(2,2,'full');
non_sym_constr=[ [1 0]*non_sym_var*[0;1]==0];

-Jason

Johan Löfberg

unread,
Apr 3, 2013, 1:51:52 PM4/3/13
to yal...@googlegroups.com
If you define the variable as a full matrix (i.e. not necessarily symmetric, 2x2 matrix parameterized by 4 variables) then the (1,2) element and (2,1) are two different variables. If you define the matrix as a symmetric variable, constraining the (1,2) variable will directly constrain the (2,1) variable, since it is the same variable.

This
non_sym_var=sdpvar(2,2,'full');
non_sym_constr=[ [1 0]*non_sym_var*[0;1]==0];

is 100% equivalent to
non_sym_var=sdpvar(2,2,'full');
non_sym_constr=[ non_sym_var(1,2)==0];

you're just doing indexation in a very cumbersome way.

Jhlaks

unread,
Apr 3, 2013, 3:09:11 PM4/3/13
to yal...@googlegroups.com
Just to make sure I am not confused.... Johan, are you saying that

non_sym_var=blkvar;
non_sym_var(1,1)=sdpvar(1);
non_sym_var(2,1)=sdpvar(1);
non_sym_var(2,2)=sdpvar(1);
non_sym_var(1,2)=0;

is equivalent to:


non_sym_var=sdpvar(2,2,'full');
non_sym_constr=[ non_sym_var(1,2)==0];


Of couse, in the actual application the non-zero and zero blocks have dimensions larger than 1x1.  In that case, would the following work?

non_sym_var=sdpvar(5,5,'full');
non_sym_constr=[ non_sym_var(1:2,4:5)==0];


Thanks again,
-Jason



Johan Löfberg

unread,
Apr 3, 2013, 3:19:39 PM4/3/13
to yal...@googlegroups.com
To begin with, let us cast the blkvar as an sdpvar so you actually compare sdpvars with sdpvars (this is done automatically if you don't do it)

non_sym_var=blkvar;
non_sym_var(1,1)=sdpvar(1);
non_sym_var(2,1)=sdpvar(1);
non_sym_var(2,2)=sdpvar(1);
non_sym_var(1,2)=0;
non_sym_var = sdpvar(non_sym_var);

is 100% equivalent to
non_sym_var =[sdpvar(1) 0;sdpvar(1) sdpvar(1)]

is 100% equivalent to
non_sym_var = sdpvar(2,2,'full');
non_sym_var(1,2)=0;


Regarding 
non_sym_var=sdpvar(2,2,'full');
non_sym_constr=[ non_sym_var(1,2)==0];

equivalence depends on what you mean with equivalence. They parameterize the same feasible space, but clearly they are not exactly the same. The first model contains 3 variables. The last model contains 4 variables, and has an equality constraint on one of them.

This
non_sym_var=sdpvar(5,5,'full');
non_sym_constr=[ non_sym_var(1:2,4:5)==0];

can just as well be accomplished with
non_sym_var=sdpvar(5,5,'full');
non_sym_var(1:2,4:5)=0;

typically no reason to optimize over variables which you know have the value 0



Jhlaks

unread,
Apr 3, 2013, 3:50:49 PM4/3/13
to yal...@googlegroups.com
Excellent!

It looks like the best/clearest way to program this would be the last option:


non_sym_var=sdpvar(5,5,'full');
non_sym_var(1:2,4:5)=0;
 
I will go with that.

Thanks for you help.

-Jason
Reply all
Reply to author
Forward
0 new messages