setting range of a variable

14 views
Skip to first unread message

Mary

unread,
Sep 9, 2014, 10:24:16 AM9/9/14
to yal...@googlegroups.com
Hi,

If i have a problem where i need to define the range of values a variable can pick, how would i do that?

for instance,
a variable T is a matrix of NXM dim, and values can be [-1,0,1]

Regards
Mary

Johan Löfberg

unread,
Sep 9, 2014, 11:11:15 AM9/9/14
to yal...@googlegroups.com
ismember

or manually (very simple when it is only -1,0 or 1)

T =-binvar(N,M,'full') + binvar(N,M,'full')

or manually more general

possiblevalues = [pi;34;-1];
 pick = binvar(N*M,length(possiblevalues),'full');
T = reshape(pick*possiblevalues,N,M);
Constraints = sum(T,2)==1;






Reply all
Reply to author
Forward
0 new messages