I need to come up with a solution for a rather, odd situation. Let's say I have an $M \times N$ matrix called ${\bf A}$, and I would like to solve it for ${\bf x}$ where $b_1 \le {\bf A} {\bf x} \le b_2$. However I also need to be able to put an upper and lower bound on each value in ${\bf x}$. Any suggestions? Linear programming is giving me some help, and doing well with $b_1$, but I'm having difficulty placing upper bounds on $b_2$.

  • $\begingroup$ ...and you want to use Mathematica to solve this problem? $\endgroup$ Commented Mar 5, 2016 at 4:16
  • $\begingroup$ That would be ideal. As it has far too many variables to do by hand. I've managed to cut it down to the 59 most important variables, but if I can get it working I would like to scale it up to over 100 in the future. $\endgroup$
    – Daniel
    Commented Mar 5, 2016 at 4:18
  • $\begingroup$ I should clarify, by linear programming I mean the Linearprogramming function within Mathematica. $\endgroup$
    – Daniel
    Commented Mar 5, 2016 at 4:20
  • $\begingroup$ @david I'm not sure about your edit. Take a look at b1<=A*x<=b2 .... if you get pinged .) $\endgroup$ Commented Mar 5, 2016 at 8:48
  • $\begingroup$ I collected some examples about how to use LinearProgramming here (mathematica.stackexchange.com/a/108655/16267). If you just want a feasible solution, without minimizing anything, you can use a zero cost vector (first argument). If you want to enforce a set constraints like $\mathbf{b}_1 \le \mathbf{Ax} \le \mathbf{b}_2$ you should double the constaints as $\mathbf{Ax} \le \mathbf{b}_2$ and $- \mathbf{Ax} \le -\mathbf{b}_1$ (second and thrid arguments). If you also want to put a lower/upper bound on each $\mathbf{x}$ component you should use the 4th argument. $\endgroup$
    – unlikely
    Commented Mar 5, 2016 at 14:10

1 Answer 1



 ConstantArray[0, Last@Dimensions@A],
 ArrayFlatten[{{A}, {-A}}],
 Join[b1, -b2]


  • $\begingroup$ This seems to have done it, thank you very much! $\endgroup$
    – Daniel
    Commented Mar 6, 2016 at 6:07
  • $\begingroup$ Doh! I just realized, I need to be able to get discrete values for certain x's. $\endgroup$
    – Daniel
    Commented Mar 6, 2016 at 6:33
  • $\begingroup$ @Daniel Integer values? This is possible by the 5th argument of LinearProgramming... $\endgroup$
    – unlikely
    Commented Mar 6, 2016 at 7:33
  • $\begingroup$ Never mind, I remembered how to do the last bit. Afraid it's been a while since I've used Mathematica. $\endgroup$
    – Daniel
    Commented Mar 6, 2016 at 7:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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