Quantcast

cube root

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

cube root

Branimir 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.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?)

 

Thx!!!

 

 


        [[alternative HTML version deleted]]

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: cube root

Niels Richard Hansen-2
?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.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?)
>
>
>
> Thx!!!
>
>
>
>
>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] 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.

--
Niels Richard Hansen                     Web:   www.math.ku.dk/~richard
Associate Professor                      Email: [hidden email]
Department of Mathematical Sciences             [hidden email]
University of Copenhagen                 Skype: nielsrichardhansen.dk
Universitetsparken 5                     Phone: +1 510 502 8161
2100 Copenhagen Ø
Denmark

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: cube root

Berend Hasselman
In reply to this post by Branimir Hackenberger
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.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
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: cube root

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)
>>
>>> 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.
>
> ______________________________________________
> [hidden email] 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

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: cube root

David Winsemius
<quote author="Tsjerk Wassenaar">
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 discussion about various approaches to fractional powers of negative numbers one can get further approaches by searching the archives.

--
David.

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
>
Tsjerk Wassenaar wrote
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.
>
> ______________________________________________
> [hidden email] 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

______________________________________________
[hidden email] 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 Wassenaar wrote
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.
>
> ______________________________________________
> [hidden email] 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

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: cube root

Sascha Vieweg
In reply to this post by Branimir Hackenberger
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.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?)

-8^(1/3) == (-8)^(1/3) # NA
-8^(1/3) == -(8^(1/3)) # TRUE

> Thx!!!

You're welcome.

--
Sascha Vieweg, [hidden email]

______________________________________________
[hidden email] 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.
Loading...