Re: [R] cube root

From: Tsjerk Wassenaar <tsjerkw_at_gmail.com>
Date: Sun, 17 Apr 2011 09:46:34 +0200

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)
>>
>>> y=x^(1/3)
>>
>>> y
>>
>>  [1]      NaN      NaN      NaN      NaN      NaN      NaN      NaN
>> NaN
>> 0.000000 1.000000
>>
>> [11] 1.259921 1.442250 1.587401 1.709976 1.817121 1.912931 2.000000
>> So, can anybody explain this?! (Why is x[1]^(1/3)=y[1]=NaN, but
>> -8^(1/3)=-2?)
>>

>
> Operator precedence.
>
> See R FAQ 7.33 Why are powers of negative numbers wrong?
>
>
> Berend
>
>
> --
> View this message in context: http://r.789695.n4.nabble.com/cube-root-tp3455020p3455027.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help_at_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.
>



-- 
Tsjerk A. Wassenaar, Ph.D.

post-doctoral researcher
Molecular Dynamics Group
* Groningen Institute for Biomolecular Research and Biotechnology
* Zernike Institute for Advanced Materials
University of Groningen
The Netherlands

______________________________________________
R-help_at_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.
Received on Sun 17 Apr 2011 - 07:50:12 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sun 17 Apr 2011 - 09:50:30 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive