Dealing with a Discontinuous ArcTan[] Function in Mathematica

In summary, the conversation discusses the use of the ArcTan function with complex arguments in Mathematica. It is noted that the function can handle complex arguments, but there may be issues with special values. The conversation also explores the possibility of a branch cut causing discrepancies in the results. The individual asks for thoughts and suggests creating a specific test to avoid the discontinuity at a certain point.
  • #1
guerom00
93
0
Hello everyone,

I copy-paste here a little bit of code:
Code:
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
 
Physics news on Phys.org
  • #2
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.
 
  • #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)…
 
  • #4
ArcTan[x] should handle complex arguments, but what does ArcTan[x,y] even mean when the arguments are complex?
 
  • #8
guerom00 said:
WTF ?! This is clearly broken, no ?
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
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 :)
 

1. How do I know if I have encountered the ArcTan[] bug in Mathematica?

The ArcTan[] bug in Mathematica is characterized by incorrect results when using the ArcTan[] function. This can happen when the inputs to the function are large numbers or when using certain combinations of inputs. If you notice unexpected or inconsistent results when using the ArcTan[] function, it is likely that you have encountered the bug.

2. Is there a way to avoid the ArcTan[] bug in Mathematica?

Yes, there are a few workarounds that can help avoid the ArcTan[] bug in Mathematica. One option is to use the ArcTan2[] function instead, which is not affected by the bug. Another option is to manually adjust the inputs to the ArcTan[] function to be within a certain range, which can prevent the bug from occurring.

3. When will the ArcTan[] bug be fixed in Mathematica?

The ArcTan[] bug has been reported to Wolfram Research, the developers of Mathematica. They are aware of the issue and are working on a fix. It is not clear when the fix will be implemented, but it is likely to be addressed in a future update or version of Mathematica.

4. Are there any other known bugs in Mathematica that I should be aware of?

Like any software, Mathematica is not immune to bugs. The best way to stay informed about known bugs is to regularly check the Wolfram Community forum, where users and developers often report and discuss issues. Additionally, Wolfram Research has a dedicated support team that can assist with any technical issues or bugs that you encounter.

5. Can I still use Mathematica for my research despite the ArcTan[] bug?

Yes, the ArcTan[] bug is only one small issue in a vast and powerful software like Mathematica. While it may cause inconvenience in some cases, there are many other functions and features in Mathematica that can still be used for research. Additionally, there are workarounds available for the ArcTan[] bug, and it is likely to be fixed in the future. If you encounter any other issues or bugs, you can always reach out to the support team for assistance.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
9
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • Calculus and Beyond Homework Help
Replies
1
Views
1K
  • Programming and Computer Science
Replies
5
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
Replies
1
Views
757
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
8K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
5K
Back
Top