Re: [R] cube root

2011-04-17 Thread Sascha Vieweg
On 11-04-17 07:51, Branimir K. Hackenberger wrote: This is some interesting: -8^(1/3) [1] -2 x=(-8:8) y=x^(1/3) y [1] NaN NaN NaN NaN NaN NaN NaN NaN 0.00 1.00 [11] 1.259921 1.442250 1.587401 1.709976 1.817121 1.912931 2.00 So,

Re: [R] cube root

2011-04-17 Thread David Winsemius
Hey :) In addition, although (-2)^3 = -8, (-8)^(1/3) != -2, mathematically. A fractional power of a negative number is complex. _Not_ in addition. The citation of FAQ 7.33 did not address the correct issue since the sequence was enclosed in parens. Yours is the only correct answer. For further

Re: [R] cube root

2011-04-17 Thread Tsjerk Wassenaar
Hey :) In addition, although (-2)^3 = -8, (-8)^(1/3) != -2, mathematically. A fractional power of a negative number is complex. And this can be obtained properly in R: > (-8+0i)^(1/3) [1] 1+1.732051i Cheers, Tsjerk >> This is some interesting: >> >>> -8^(1/3) >> >> [1] -2 >> >>> x=(-8:8) >> >>

Re: [R] cube root

2011-04-16 Thread Berend Hasselman
Branimir K. Hackenberger wrote: > > This is some interesting: > >> -8^(1/3) > > [1] -2 > >> x=(-8:8) > >> y=x^(1/3) > >> y > > [1] NaN NaN NaN NaN NaN NaN NaN > NaN > 0.00 1.00 > > [11] 1.259921 1.442250 1.587401 1.709976 1.817121 1.912931 2

Re: [R] cube root

2011-04-16 Thread Niels Richard Hansen
?Syntax for precedence of operators. On 16/04/11 22.51, Branimir K. Hackenberger wrote: This is some interesting: -8^(1/3) [1] -2 x=(-8:8) y=x^(1/3) y [1] NaN NaN NaN NaN NaN NaN NaN NaN 0.00 1.00 [11] 1.259921 1.442250 1.587401

[R] cube root

2011-04-16 Thread Branimir K. Hackenberger
This is some interesting: > -8^(1/3) [1] -2 > x=(-8:8) > y=x^(1/3) > y [1] NaN NaN NaN NaN NaN NaN NaN NaN 0.00 1.00 [11] 1.259921 1.442250 1.587401 1.709976 1.817121 1.912931 2.00 So, can anybody explain this?! (Why is x[1]^(1/3)=y

Re: [R] cube root of a negative number

2010-10-26 Thread Prof Brian Ripley
In this particular case it is part of the C99 stanadrd (7.12.7.4) for the 'pow' function R uses. On Wed, 27 Oct 2010, Berwin A Turlach wrote: G'day Gregory, On Tue, 26 Oct 2010 19:05:03 -0400 Gregory Ryslik wrote: Hi, This might be me missing something painfully obvious but why does the cu

Re: [R] cube root of a negative number

2010-10-26 Thread Berwin A Turlach
G'day Bill, On Wed, 27 Oct 2010 10:34:27 +1100 wrote: [...] > It is no surprise that this does not work when working in the real > domain, except "by fluke" with something like > > > -4^(1/3) > [1] -1.587401 > > > > where the precedence of the operators is not what you might expect. > Now th

Re: [R] cube root of a negative number

2010-10-26 Thread Jeff Newmiller
Because it is implemented as antilog((1/3)*log(-4)) most likely using base 2 for the log/antilog functions. "Gregory Ryslik" wrote: >Hi, > >This might be me missing something painfully obvious but why does the >cube root of the following produce an NaN? > >> (-4)^(1/3) >[1] NaN >> > >As we ca

Re: [R] cube root of a negative number

2010-10-26 Thread Spencer Graves
what you might expect. Now that could be considered a bug, since apparently -4^(1/2) [1] -2 which comes as rather a surprise! Bill. -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Kjetil Halvorsen Sent: Wednesday, 27 October

Re: [R] cube root of a negative number

2010-10-26 Thread Berwin A Turlach
G'day Gregory, On Tue, 26 Oct 2010 19:05:03 -0400 Gregory Ryslik wrote: > Hi, > > This might be me missing something painfully obvious but why does the > cube root of the following produce an NaN? > > > (-4)^(1/3) > [1] NaN 1/3 is not exactly representable as a binary number. My guess is tha

Re: [R] cube root of a negative number

2010-10-26 Thread Bill.Venables
ight expect. Now that could be considered a bug, since apparently > -4^(1/2) [1] -2 which comes as rather a surprise! Bill. -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Kjetil Halvorsen Sent: Wednesday, 27 October 2010 9:17

Re: [R] cube root of a negative number

2010-10-26 Thread sachinthaka . abeywardana
hmm interesting. When I did -4^(1/3) got the correct answer, but then again that's because it processes the negative later. i.e. -4^(1/2) gave me -2 instead of the 2i I expected. Also when I did (-4+0i)^(1/3) it gave me 0.793701+1.37473i. Possible bug? Sachin --- Please consider the environment b

Re: [R] cube root of a negative number

2010-10-26 Thread Kjetil Halvorsen
Look at this: > x <- as.complex(-4) > x [1] -4+0i > x^(1/3) [1] 0.793701+1.37473i > (-4)^(1/3) [1] NaN It seems that R gives you the principal root, which is complex, and not the real root. Kjetil On Tue, Oct 26, 2010 at 8:05 PM, Gregory Ryslik wrote: > Hi, > > This might be me missing somethi

[R] cube root of a negative number

2010-10-26 Thread Gregory Ryslik
Hi, This might be me missing something painfully obvious but why does the cube root of the following produce an NaN? > (-4)^(1/3) [1] NaN > As we can see: > (-1.587401)^3 [1] -4 Thanks! Greg __ R-help@r-project.org mailing list https://stat.ethz.c

Re: [R] cube root on array

2009-12-12 Thread Marc Schwartz
On Dec 12, 2009, at 9:31 AM, Rodrigo Tsai wrote: Dear R developers, is that right? -27^(1/3) [1] -3 library(fortunes) > fortune("^") Thomas Lumley: The precedence of ^ is higher than that of unary minus. It may be surprising, [...] Hervé Pagès: No, it's not surprising. At least to me...

[R] cube root on array

2009-12-12 Thread Rodrigo Tsai
Dear R developers, is that right? > -27^(1/3) [1] -3 > c(-27,27)^(1/3) [1] NaN 3 i'm using sign( c(-27,27) ) * abs( c(-27,27)) ^(1/3) , thanks [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/m