0
$\begingroup$

When I use Mathematica to calculate some roots of an quadratic equation, it will output the simplified answer like $\frac{-w \sqrt{-h} \sqrt{4 \theta ^2 p-4 \theta p-h}+h w+2 \theta p w}{2 \theta ( p+h)}$. In this solution, $r, p$ are both required to be nonnegative. So the answer given by Mathematica may result in Imaginary solution. I knew that Mathematica has given an option that "Assumption". But when the solving equation is complex, the computation time is unbearable. So is there another method to get correct result? Or is there some simple method to calculate the product of two squared root terms?

Here is an example:

eqn = (p (p (v - w)^2 \[Theta] + h v (-w + v \[Theta])))/(2 (h + p) v)
Solve[eqn == 0, v]

The result is $$\left\{\left\{v\to \frac{-\sqrt{-h} w \sqrt{-h+4 \theta ^2 p-4 \theta p}+h w+2 \theta p w}{2 (h \theta +\theta p)}\right\},\left\{v\to \frac{\sqrt{-h} w \sqrt{-h+4 \theta ^2 p-4 \theta p}+h w+2 \theta p w}{2 (h \theta +\theta p)}\right\}\right\}$$

$\endgroup$
2
  • 2
    $\begingroup$ sol = Simplify[Solve[eqn == 0, v], {h >= 0, p >= 0}] $\endgroup$
    – Bob Hanlon
    Commented Jun 30, 2022 at 14:59
  • $\begingroup$ This answer also work! Thanks!! $\endgroup$
    – Wynn
    Commented Jul 1, 2022 at 2:55

1 Answer 1

0
$\begingroup$

I am not entirely sure about what you were asking.. But if you want to give assumptions to Mathematica, you can do it like this, and it often reduces computation time rather than making it longer:

eqn = (p (p (v - w)^2 \[Theta] + h v (-w + v \[Theta])))/(2 (h + p) v);
FullSimplify[
 Assuming[Element[r, NonNegative] && Element[p, NonNegative], 
  Solve[eqn == 0, v]]]
Timing[%]

Which gives the results enter image description here

Where computation time is neglectible.

$\endgroup$
1
  • $\begingroup$ Sorry for my poor English and your understanding is right. I'm a newer to Mathematica. And I used Solve[eqn==0, v, Assumptions -> {h >=0, p >= 0, \[Theta] >=0}] to find these roots, which is proved to be time-consuming. Maybe it is a bad usage for this situation. And my problem description is different from the example that h is replaced by r*p. It may confused you $\endgroup$
    – Wynn
    Commented Jul 1, 2022 at 2:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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