The correct mathematical "answer" is really one (or perhaps all
three?) of three complex numbers that are the solutions to x^3+8=0.
Here is one of the others:
> as.complex(-8)^(1/3)
[1] 1+1.732051i
I suspect there is a reason why R is willing to produce this
particular solution and not the other two after being told to use the
complex range, but I don't know the reason.
You can get all three with:
> polyroot(c(8,0,0,1))
[1] 1+1.732051i -2+0.000000i 1-1.732051i
--
David.
On Jul 18, 2009, at 6:04 PM, Dave DeBarr wrote:
Why does the expression "(-8)^(1/3)" return NaN, instead of -2?
This is not answered by
http://cran.r-project.org/doc/FAQ/R-FAQ.html#Why-are-powers-of-negative-numbers-wrong_003f
Thanks,
Dave
David Winsemius, MD
Heritage Laboratories
West Hartford, CT
______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.