Message Boards Message Boards

0
|
3957 Views
|
3 Replies
|
1 Total Likes
View groups...
Share
Share this post:

Errors in defining variables (binary) and equalitites

Posted 4 years ago

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].

POSTED BY: Wael Al Hajailan
3 Replies
Posted 4 years 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
POSTED BY: Bill Nelson
Posted 4 years 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

POSTED BY: Bill Nelson

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 BY: Wael Al Hajailan
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