I want to select positive solutions to Solve[], but as the sign of the solutions depend on the value of some parameters/other variable, I am not sure how to do this?

For example, how do I select the positive solution of $x^2=a^2$ given that a is positive? My code below doesn't work...

Select[sol, (x/.#)>0&]

Also, could I have specified this directly in the Solve function, solving only for x positive knowing that a is positive?


  • $\begingroup$ Simplify[Solve[x^2 == a^2 && x > 0 && a > 0, x, Reals], Assumptions -> {a > 0}]? $\endgroup$ – kglr Apr 9 '16 at 3:35

You can use Reduce

Reduce[x^2==a^2&& x>0,x,Reals]

which gives you two solutions depending on the sign of a:

(a < 0 && x == Sqrt[a^2]) || (a > 0 && x == Sqrt[a^2])

So if you make it more strict you will get one solution:

Reduce[x^2==a^2&& x>0&& a>0,x,Reals]

a > 0 && x == a

  • $\begingroup$ Nice, thanks @MathX! Is there however any way I could use based on the output from Solve? Thanks! $\endgroup$ – Matifou Apr 9 '16 at 2:24
  • $\begingroup$ Solve[{x^2 == a^2, a > 0, x > 0}, x] // Simplify[#, a > 0] & evaluates to {{x -> a}} $\endgroup$ – Bob Hanlon Apr 9 '16 at 4:50

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.