# Select positive solution based on value of parameter

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...

sol=Solve[x^2==a^2,x]
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?

Thanks!

• Simplify[Solve[x^2 == a^2 && x > 0 && a > 0, x, Reals], Assumptions -> {a > 0}]? – 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

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