# Selecting results according to the constraint [duplicate]

It is very likely that this question is a duplicate, but unfortunately I have not found the solution.

Among the results of a Solve, I would like to apply for the Variable x a Real and Positive value.

My attempt:

ClearAll["Global*"]
sol = Solve[x^4 - x^2 - 5 == 0, x]
SelectFirst[sol, Real]
SelectFirst[sol, {Real, Positive}]


$\left\{\left\{x\to -i \sqrt{\frac{1}{2} \left(\sqrt{21}-1\right)}\right\},\left\{x\to i \sqrt{\frac{1}{2} \left(\sqrt{21}-1\right)}\right\},\left\{x\to -\sqrt{\frac{1}{2} \left(\sqrt{21}+1\right)}\right\},\left\{x\to \sqrt{\frac{1}{2} \left(\sqrt{21}+1\right)}\right\}\right\}$

$---$

$---$

I made a small variation of the above code by adding /. Rule -> Set

ClearAll["Global*"]
sol = Solve[x^4 - x^2 - 5 == 0, x] /. Rule -> Set
x
SelectFirst[sol, Real]
SelectFirst[sol, {Real, Positive}]


$\left( \begin{array}{c} -i \sqrt{\frac{1}{2} \left(\sqrt{21}-1\right)} \\ i \sqrt{\frac{1}{2} \left(\sqrt{21}-1\right)} \\ -\sqrt{\frac{1}{2} \left(\sqrt{21}+1\right)} \\ \sqrt{\frac{1}{2} \left(\sqrt{21}+1\right)} \\ \end{array} \right)$

$\sqrt{\frac{1}{2} \left(\sqrt{21}+1\right)}$

$---$

$---$

I was able to apply the desired value to the Variable x, but I could not do anything with the Variable sol. What am I doing wrong?

• Why not include the constraint in the Solve?: sol = Solve[x^4 - x^2 - 5 == 0 && x > 0, x] – Carl Woll May 31 '17 at 15:42
• Possible duplicate of Solve an equation in $\mathbb{R}^+$. It would be reasonable to examine also this post: First positive root – Artes May 31 '17 at 15:44
• or use Select[sol, Element[#, Reals] && # > 0 &] – egwene sedai May 31 '17 at 15:50
• @egwenesedai I think x>0 already implies Element[x, Reals], wich already evaluates to True|False so no need for Equal (==) either. – rhermans May 31 '17 at 15:54
• @rhermans yes, you are right that == is not necessary; Element[x, Reals] is to safeguard against the warning invalid comparison with [complex number] attempted.. – egwene sedai May 31 '17 at 16:00

Reduce[{x^4 - x^2 - 5 == 0, x > 0}, x, Reals] 