3
$\begingroup$

I have a complicated symbolic expression which contains many terms like $(a/(a-2))^{1/m}$, where $a/(a-2)$ could be positive or negative after replacement.

I only need the real root after replacement, but Power[] function in Mathematica most of the time gives me a complex number instead. I found something that almost suits my need here (the realPower function by Peter Breitfeld), but I have a hard time get it working in the way I want.

For example:

((a/(-2 + a))^(1/3) /. {x_^y_ :> realPower[x, y]}) /. {a -> 0.5}

still gives me a complex number. (it seems that realPower only work with numerical values) What should I do to get only the real root after replacement?

$\endgroup$
1
  • $\begingroup$ If you read another answers to the question you linked to in your post you wouldn't have asked this one. $\endgroup$
    – Artes
    Commented Sep 25, 2013 at 21:25

1 Answer 1

8
$\begingroup$

Surd is your friend:

Surd[a/(-2 + a), 3] /. a -> 0.5

-0.693361

It can be entered in formatted form as Esc surd Esc.

enter image description here

Surd was introduced in Mathematica 9. In previous versions you can use

((a/(-2 + a))^(1/3) /. {x_^y_ :> Sign[x] Abs[x]^y}) /. {a -> 0.5}

-0.693361

$\endgroup$

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