Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to define a binary variable in matlab?

570 views
Skip to first unread message

Xu Wang

unread,
Jul 30, 2010, 6:30:01 AM7/30/10
to
Hi everyone,

I want to represent MIN{y,z} = 5 in matlab by the following equations.

y >= 5
y <= 5*x + 20*(1-x)
z >= 5
z <= 5*(1-x) + 20*x

Therefore, the variable x should be a binary variable. Is there anyway
to define/declare x as a binary variable? I have searched online and
have not found any method to do it.

Thank you in advance.

Xu

Xu Wang

unread,
Jul 30, 2010, 6:39:27 AM7/30/10
to
On Jul 30, 12:30 pm, Xu Wang <wangxu.n...@gmail.com> wrote:
> Hi everyone,
P.S. There is a method to use logic(x) to get binary values, but there
are two disadvantages:

1. the possibilities of 0 and 1 is not equal. If x is 0, logic(x) is
0, otherwise, logic(x) is 1.
2. I think it is impossible to put a function in a matrix, because I
want to use the equations in linear programming problems.

Additional information is in this post
http://groups.google.com/group/sci.math/browse_thread/thread/51f93c35bab4cbcf#.

Xu

Yi Cao

unread,
Jul 30, 2010, 6:46:03 AM7/30/10
to
Xu Wang <wangx...@gmail.com> wrote in message <9acb49a0-3e6d-4c8d...@g35g2000yqa.googlegroups.com>...

You can define x as a binary variable by using either x = true or x = false. However, equations you presented in the post is not a clear descrption of what you want to do.

Good luck.
Yi

Xu Wang

unread,
Jul 30, 2010, 6:53:04 AM7/30/10
to
On Jul 30, 12:46 pm, "Yi Cao" <y....@cranfield.ac.uk> wrote:
> Xu Wang <wangxu.n...@gmail.com> wrote in message <9acb49a0-3e6d-4c8d-b95b-d8f8c7fcc...@g35g2000yqa.googlegroups.com>...

Thank you.

I want to solve a mixed integer programming problem in matlab.

MIN = x1+x2+x3+x4;
x1 + x2 >= 5;
x3 + x4 >= 5;
x1 + x2 <= 5*y1 + 200*(1-y1);
x3 + x4 <= 5*(1-y1) + 200*y1;
x2 >= 3;
x3+x4 >= 3;
x2 <= 3*y2 + 100*(1-y2);
x3+x4 <= 3*(1-y2) + 200*y2;
@BIN(y1);
@BIN(y2);

Here, y1 and y2 are binary valued variables. Their value should be 0
or 1. The code above is in Lingo/Lindo style. I want to represent it
in matlab.

Xu

Yi Cao

unread,
Jul 31, 2010, 4:10:23 PM7/31/10
to
Xu Wang <wangx...@gmail.com> wrote in message <3691e5c6-2c1e-4ea6...@f42g2000yqn.googlegroups.com>...

> Thank you.
>
> I want to solve a mixed integer programming problem in matlab.
>
> MIN = x1+x2+x3+x4;
> x1 + x2 >= 5;
> x3 + x4 >= 5;
> x1 + x2 <= 5*y1 + 200*(1-y1);
> x3 + x4 <= 5*(1-y1) + 200*y1;
> x2 >= 3;
> x3+x4 >= 3;
> x2 <= 3*y2 + 100*(1-y2);
> x3+x4 <= 3*(1-y2) + 200*y2;
> @BIN(y1);
> @BIN(y2);
>
> Here, y1 and y2 are binary valued variables. Their value should be 0
> or 1. The code above is in Lingo/Lindo style. I want to represent it
> in matlab.
>
> Xu

You can download some MILP solvers from the File Exchange, for example

http://www.mathworks.com/matlabcentral/fileexchange/6990

HTH
Yi

0 new messages