4
$\begingroup$

Say for example I am doing the following in Mathematica

Reduce[x1 >= 0 &&
-4*x1 <= 16 &&
4*x1 >= 16 ||
x1 <= 0 &&
4*x1 <= 16 &&
-4*x1 >= 16, {x1}]

This returns $x_1 \leq -4 \;\;||\;\; x_1 \geq 4$. How would I make Mathematica return the bounded parts of the region? I.e. is there some function I can do to these inequalities so that I can return -4 or 4. E.g. I can type bound1[system] and that gives -4, and then bound2[system] and that gives 4. Is that possible?

Thanks

$\endgroup$

3 Answers 3

4
$\begingroup$

Maybe something like this? I don't know if this is what you meant?

sol=Reduce[x1 >= 0 &&-4*x1 <= 16 &&4*x1 >= 16 ||x1 <= 0 &&4*x1 <= 16 &&-4*x1 >= 16, {x1}];
sol[[1, 2]]
(*-4*)
sol[[2, 2]]
(*4*)
$\endgroup$
4
  • $\begingroup$ Amazing, that is quite cheeky just realized that what you have just shown me is that Mathematica can store solutions as strings and then you can manipulate each part of the solution separately and access the character? Am I right in assuming that? $\endgroup$
    – Kadir
    Aug 18, 2014 at 20:53
  • $\begingroup$ you are quit correct. the solution is basically translated internally using what is called FullForm. if you want to get any thing, you need to know the level of that thing in the fullForm. you can assume things stored like if they were in lists and you need to know the position of that thing you want to extract. $\endgroup$ Aug 18, 2014 at 20:59
  • 2
    $\begingroup$ I swear Mathematica is absolutely incredible... May have to apply to work there once I graduate... $\endgroup$
    – Kadir
    Aug 18, 2014 at 21:00
  • $\begingroup$ @Kadir You should know that they're not really "strings" so to speak. They're Mathematica expressions. You can investigate results with FullForm (or TreeForm) and Part. $\endgroup$
    – evanb
    Aug 18, 2014 at 22:16
2
$\begingroup$

I don't want to compete with Algohi's nice answer, but - as to my experience - Reduce can be almost always replaced with Simplify or FullSimplify:

res = Simplify[x1 >= 0 && -4*x1 <= 16 && 4*x1 >= 16 || x1 <= 0 && 4*x1 <= 16 && -4*x1 >= 16]

Cases[res, _?NumberQ, -1]

{-4, 4}

$\endgroup$
2
$\begingroup$

Here's another way (in M10 only):

Cases[
  NumberLinePlot[x1 >= 0 && -4*x1 <= 16 && 4*x1 >= 16 || x1 <= 0 && 4*x1 <= 16 && -4*x1 >= 16, x1], 
  Point[{x_, _}] :> x, \[Infinity]
]

(* {-4, 4} *)
$\endgroup$

Your Answer

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

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