Message Boards Message Boards

GROUPS:

Errors in defining variables (binary) and equalitites

Posted 1 month ago
360 Views
|
3 Replies
|
1 Total Likes
|

Hi, I got those two errors when debugging my code:

Set::write: Tag Plus in a0+b0 is Protected.

NMinimize::ivar: z0+2 z1+3 z2+4 z3 is not a valid variable.

I don't what are the problem? However,I have defined the following:

npm1 = z0 1 + z1 2 + z2 3 + z3 4;
z0 + z1 + z2 + z3 = 1;
0 <= z0 <= 1; 0 <= z1 <= 1, 0 <= z2 <= 1, 0 <= z3 <= 1, 0 <= z4 <= 1

The variables should be binary [0,1].

3 Replies
Posted 1 month ago

Try

npm1 = z0 1 + z1 2 + z2 3 + z3 4;
NMinimize[{npm1,z0+z1+z2+z3==1&&0<=z0<=1&&0<=z1<=1&&0<=z2<=1&&0<=z3<=1},{z0,z1,z2,z3}]

If you want to constrain your variables to be 0 or 1 then you should look at

Element[z0,Integers]&&0<=z0<=1

Otherwise your variables can have any value between 0 and 1

Should I use "&&" between defining the constraints? I have already defined them as integers:

{a0, a1, a2, a3, b0, b1, b2, b3, z0, z1, z2, z3} \[Element] Integers}

So, why it is not a valid variable ? and protected? Thanks,

Posted 1 month ago

This

Set::write: Tag Plus in a0+b0 is Protected.

error is probably because of using = instead of == in

z0+z1+z2+z3==1
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract