1
$\begingroup$

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?

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

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}} *)
$\endgroup$

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.