Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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

share|improve this question

3 Answers 3

up vote 4 down vote accepted

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*)
share|improve this answer
    
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? –  Kadir Aug 18 at 20:53
    
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. –  Algohi Aug 18 at 20:59
2  
I swear Mathematica is absolutely incredible... May have to apply to work there once I graduate... –  Kadir Aug 18 at 21:00
    
@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. –  evanb Aug 18 at 22:16

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}

share|improve this answer

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} *)
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.