2
$\begingroup$

This question already has an answer here:

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?

$\endgroup$

marked as duplicate by Artes, Carl Woll, m_goldberg, Bob Hanlon, Community May 31 '17 at 19:22

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

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

There are days when you have forgotten everything ...

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

enter image description here

$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.