# Solving for positive square root of an equation, using assumptions

Is there a way to get the positive square root, while solving an equation. So far, this is what I am doing :

    \$Assumptions = {{beta ,K , m, c} > 0, Element[{beta ,K , m, c}, Reals] }

Solve[K==((1/Sqrt[1-beta^2])-1)*m*c^2,beta]


which gives me two solutions.

                                       2                                   2
Sqrt[K] Sqrt[K + 2 c  m]            Sqrt[K] Sqrt[K + 2 c  m]
Out[14]= {{beta -> ------------------------}, {beta -> ------------------------}}
2                                   2
-K - c  m                            K + c  m


But I am only interested in the positive solution, for which I have been doing

   beta = Solve[K==(gamma-1)*m*c^2,beta][[All,1,2]][[2]]


which gives me

                             2
Sqrt[K] Sqrt[K + 2 c  m]
Out[15]= ------------------------
2
K + c  m


But is there a way to check which is positive and negative based on the assumptions I have made, and then choose the positive one?

Thanks much!

• Probably you find the solution extraction via Part more convenient, but in case you didn't know (i'm just saying this because i used to didn't know better about the advantages of letting the rule there), you can also write beta/.Solve[eq,beta][[2]] to get the value of beta. This has the advantage that you can save the solution and use it in multiple places without polluting your namespace by assigning the solution to the variable name directly (which leads to instant replacement which you can't control individually anymore). E.g. sol=Solve[eq,beta][[2]];{beta*v,1-beta^2}/.sol. – Thies Heidecke Nov 8 '18 at 19:22

Solve doesn't make use of Assumptions. Also, your first assumption doesn't mean anything. So, inserting positivity constraints into Solve yields:

soln = Solve[K == ((1/Sqrt[1-beta^2])-1) m c^2 && beta>0 && m>0 && c>0 && K>0, beta]


{{beta -> ConditionalExpression[Sqrt[(K^2 + 2 c^2 K m)/(K + c^2 m)^2], K > 0 && c > 0 && m > 0]}}

You can eliminate the ConditionalExpression using Simplify:

Simplify[soln, m>0 && c>0 && K>0]


{{beta -> Sqrt[K (K + 2 c^2 m)]/(K + c^2 m)}}

Try this:

    Reduce[k == ((1/Sqrt[1 - beta^2]) - 1)*m*c^2 && m > 0 && beta > 0 &&
k > 0 && c > 0, beta]

(*  k > 0 && c > 0 && m > 0 &&
beta == Sqrt[(k^2 + 2 c^2 k m)/(k + c^2 m)^2]  *)


Have fun!

Map[Sqrt,