help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [newbie] unexpected behaviour for x^x


From: Julien Bect
Subject: Re: [newbie] unexpected behaviour for x^x
Date: Fri, 12 Dec 2014 13:40:16 +0100
User-agent: Mozilla/5.0 (X11; Linux i686; rv:31.0) Gecko/20100101 Thunderbird/31.3.0

Le 12/12/2014 13:16, Jean Dubois a écrit :
I was surprised to found out that when I calculated x^x with octave, using 
floats which approach zero I get two different results depending on the 
direction
in which zero is approached, this is what I mean:

octave:1> 0.001^0.001
ans =  0.99312

octave:2> -0.001^-0.001
ans = -1.0069

Hello Jean,

First thing, be careful with operator precedence:

   octave:1> -0.001^-0.001== - (0.001 ^ (- 0.001))
   ans =  1

So the minus sign in front of your second expression gives the minus sign in front of your second result, nothing surprising.


Now, without the minus sign, I get

  octave:1> format short

  octave:2> 0.001^0.001
  ans =  0.99312

  octave:3> 0.001^-0.001
  ans =  1.0069

which is the correct result, because

   octave:4> 1 / (0.001^-0.001)
   ans =  0.99312


Last thing, x^x with a negative x will give you a complex result, but still converging to 1:

   octave:5> (-0.001) ^ (-0.001)
   ans =     1.00692669984728 -  0.00316336393000065i

   octave:6> (-1e-10) ^ (-1e-10)
   ans =     1.00000000230259 - 3.14159266082358e-10i


I hope this helps.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]