Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

[Mathematica] ArcTan[] bug ?

  1. Oct 26, 2011 #1
    Hello everyone,

    I copy-paste here a little bit of code:
    Code (Text):
    In[4417]:= x = (1.5` + 0.` I);
    y = (0.` + 0.` I);

    (* 1 *) ArcTan[x, y]
    (* 2 *) ArcTan[x // Chop, y // Chop]
    (* 3 *) -I Log[(x + I y)/Sqrt[x^2 + y^2]]
    {y == 0, Re[y] == 0, Im[y] == 0, Im[x] == 0}

    Out[4419]= -1.5708 + 0. I

    Out[4420]= 0

    Out[4421]= 0. + 0. I

    Out[4422]= {True, True, True, True}
    The quantities x and y are calculated elsewhere.
    The expression 1 for the arctangent is wrong since it gives me -pi/2 :confused:
    In expression 2, I chop the arguments and the result is right.
    Expression 3 is used when x or y is complex and gives the right answer as well.
    Finally, some tests…

    Any thoughts ?
    TIA
     
  2. jcsd
  3. Oct 26, 2011 #2

    phyzguy

    User Avatar
    Science Advisor

    I agree it looks wrong, but I think ArcTan[x,y] is assuming x and y are both real. It must have a problem when thy are complex.
     
  4. Oct 26, 2011 #3
    The help page of ArcTan[x,y] indicates that it can handle complex arguments. It then uses the expression which involves the Log[] I gave.
    Problem is: my quantities x and y are not complex according to the tests I make… Which is strange because I thought that the number 0.` is different from 0 (== wise)…
     
  5. Oct 26, 2011 #4

    phyzguy

    User Avatar
    Science Advisor

    ArcTan[x] should handle complex arguments, but what does ArcTan[x,y] even mean when the arguments are complex?
     
  6. Oct 26, 2011 #5
    Like I said : http://reference.wolfram.com/mathematica/ref/ArcTan.html
    Click the “More Information” and have a look at the last bullet :)

    ArcTan[x,y] is simply ArcTan[y/x]. If x or y are complex, y/x is a complex number… No problem here.
     
  7. Oct 26, 2011 #6

    Hurkyl

    User Avatar
    Staff Emeritus
    Science Advisor
    Gold Member

  8. Oct 26, 2011 #7
    Last edited: Oct 26, 2011
  9. Oct 26, 2011 #8

    Hurkyl

    User Avatar
    Staff Emeritus
    Science Advisor
    Gold Member

    No and yes.

    No, in the sense that you should expect numerical algorithms to misbehave at special values. Yes, in the sense that it's a little surprising these values are special.


    What's most likely happening internally is that there is an algebraic identity being used and your point is right on a branch cut of the terms involved. And because your numbers are approximate, different sides of the branch cut wind up being used in different terms.
     
  10. Oct 26, 2011 #9

    Hurkyl

    User Avatar
    Staff Emeritus
    Science Advisor
    Gold Member

  11. Oct 27, 2011 #10
    I see now… :)
    Well, that doesn't solve my problem: I now have a function of this angle (I use this ArcTan[] to calculate an angle, obviously) which is discontinuous at one point… I'll have to make a specific test to avoid this very point.

    Thanks :)
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: [Mathematica] ArcTan[] bug ?
  1. Mathematica bug? (Replies: 5)

  2. Bug with mathematica (Replies: 1)

Loading...