Am 12.08.2020 um 19:12 schrieb Alecos Papadopoulos:
Let X be a series of negative numbers. Then the command
series Y = X^(1/3)
(or any other "1/oddnumber" fractional power)
returns a "Warning: pow: Domain error" message, overwrites series
"Y"
and returns a "no valid values" if one attempts to view the series.
Why is this happening, considering that X^(1/3) is a real number even if
X is a negative number?
Good question. I'm noticing that 'eval -1^(1/3)' works fine, in contrast.
Now, consider series "Z" which has both positive /and/
negative values.
We want to compute
W = Z^(1/3)
Given a recent new feature in gretl, the sign function sgn(), I guess
we can avoid the obvious conditional if-else statement, and compute W
by writing
W = sgn(Z) * (abs(Z)^(1/3))
that covers also the case of Z taking an exact zero value.
Is this the proper/efficient way?
Only testing will tell if it's efficient, but my guess would be that the
paper-and-pencil-style multiplication with the sign might not be
optimal. Perhaps like this:
series W = (Z < 0) ? -(abs(Z)^(1/3)) : Z^(1/3)
cheers
sven