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?

  • 3
    $\begingroup$ Could you add a small, complete example ? $\endgroup$ Dec 19, 2013 at 16:04

1 Answer 1


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

getLinearForm[ineqs : {(_LessEqual | _GreaterEqual) ..}, vars_] := 
  {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}} *)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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