Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a list of linear inequalities, and I want to get it into the form $A\ x \leq b$; i.e., find the matrix $A$ and the vector $b$. Is there any function in Mathematica that can that can do this?

share|improve this question
3  
Could you add a small, complete example ? – b.gatessucks Dec 19 '13 at 16:04
up vote 7 down vote accepted

Basically it amounts to using CoefficientArrays along with a bit of massaging for sense of inequality.

getLinearForm[ineqs : {(_LessEqual | _GreaterEqual) ..}, vars_] := 
 Module[
  {mults, lpolys, rhs, lhs},
  mults = Map[Head, ineqs] /. {LessEqual -> 1, GreaterEqual -> -1};
  lpolys = mults*Apply[Subtract, ineqs, {1}];
  {rhs, lhs} = Normal[CoefficientArrays[lpolys, vars]];
  {lhs, -rhs}
  ]

Quick example.

vars = {x, y};
ineqs = {a x + b y <= 3, c x + d y >= 7};

getLinearForm[ineqs, vars]

(* Out[302]= {{{a, b}, {-c, -d}}, {3, -7}} *)
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.