# binary

Tags:

Updated:

binary is used to constrain a variable to be binary.

### Syntax

F = binary(x)


### Examples

Setting up a binary linear program can be done as

x = binvar(n,1);
optimize(A*x<b,c'*x)


or

x = sdpvar(n,1);
optimize([A*x<=b, binary(x)],c'*x)


The binary constraint is imposed on the involved variables, not the actual expression. Hence, the following two constraints are equivalent

F = binary(x);
F = binary(pi+sqrt(2)*x);


### Comment

If possible, use binvar instead as there are some parts in YALMIP where it can exploit integrality on an earlier stage if the varaibles have been defined as such.