“Error using logical Conversion to logical from constraint is not possible."

701 views
Skip to first unread message

Ding YiFan

unread,
Apr 29, 2016, 10:20:58 AM4/29/16
to YALMIP
when I use the following syntax in the model,  I get the following error:

“Error using logical
Conversion to logical from constraint is not possible."

Error in DataOfUsers (line 150)
    if IfTransfer(i)==-2

 I define that "IfTransfer=binvar(10,1); "

for i=1:10                                                  
    if IfTransfer(i)==-2
            for j=1:22
                DataOfLoad1(i,j)=DataOfLoad0(i,j+2);
            end
            DataOfLoad1(i,23)=DataOfLoad0(i,1);
            DataOfLoad1(i,24)=DataOfLoad0(i,2);
            DataOfLoad0(i,:)=0;
    elseif IfTransfer(i)==-1
            for j=1:23
                DataOfLoad1(i,j)=DataOfLoad0(i,j+1);
            end
            DataOfLoad1(i,24)=DataOfLoad0(i,1);
            DataOfLoad0(i,:)=0;
    elseif IfTransfer(i)==0
            for j=1:23
                DataOfLoad1(i,j)=DataOfLoad0(i,j);
            end
            DataOfLoad0(i,:)=0;
    elseif IfTransfer(i)==1
            for j=2:24
                DataOfLoad1(i,j)=DataOfLoad0(i,j-1);
            end
            DataOfLoad1(i,1)=DataOfLoad0(i,24);
            DataOfLoad0(i,:)=0;
    elseif IfTransfer(i)==2
            for j=3:24
                DataOfLoad1(i,j)=DataOfLoad0(i,j-2);
            end
            DataOfLoad1(i,1)=DataOfLoad0(i,23);
            DataOfLoad1(i,2)=DataOfLoad0(i,24);
            DataOfLoad0(i,:)=0;
    end
end


so what can I do?

Johan Löfberg

unread,
Apr 29, 2016, 10:52:04 AM4/29/16
to YALMIP

Ding YiFan

unread,
May 3, 2016, 8:18:48 AM5/3/16
to YALMIP
Sorry, I still do not know how to  solve this problem. And I can  not understand the function of ‘implies’. If I can not use 'if', how can I compare sdpvar with matrix?

Johan Löfberg

unread,
May 3, 2016, 9:20:20 AM5/3/16
to YALMIP
To code the logical condition 

if x % x is a binary variable
 z == 1
end

You add the constraint implies(x, z==1);

Simarily more general

if x >= 23
 z == 1
end

You add the constraint implies(x>=23, z==1);

Ding YiFan

unread,
May 3, 2016, 9:08:08 PM5/3/16
to YALMIP

Oh, thank you! I have understood ‘implies'. However, how should I rewrite the following cede?

 for j=1:22
               DataOfLoad1(i,j)=DataOfLoad0(i,j+2);
           end
           DataOfLoad1(i,23)=DataOfLoad0(i,1);
           DataOfLoad1(i,24)=DataOfLoad0(i,2);
           DataOfLoad0(i,:)=0;
 I do not think I can add it as a parameter of 'implies( , )'.

Johan Löfberg

unread,
May 4, 2016, 3:14:45 AM5/4/16
to YALMIP
parameter?


why don't you simply write x(1) == x(3:2:23), x(2) == x(2:2:24)


Reply all
Reply to author
Forward
0 new messages