Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DualNumbers and ArcTan[x,y] #7

Open
rudolfoldenbourg opened this issue Jan 18, 2024 · 2 comments
Open

DualNumbers and ArcTan[x,y] #7

rudolfoldenbourg opened this issue Jan 18, 2024 · 2 comments

Comments

@rudolfoldenbourg
Copy link

Dear Sjoerd,
I continue to look for the best approach to minimize a mean squared error function that has many variables connected in part by trigonometric functions, among them ArcTan[x,y].

In using DualNumbers, I noticed that ArcTan[Dual[x,dx],Dual[y,dy]] remains unevaluated, both, the Standard and NonStandard part, while ArcTan[Dual[y,dy]/Dual[x,dx]] seems to evaluates to the correct result when x and y are both positive. As is well known, difficulties arise when x and/or y become negative, as the quadrants need to be considered for evaluating to the correct angle. Therefore, Mathematica implements the ArcTan[x,y] version of the function to keep track of the quadrants the sign of the x and y variables are pointing to.

Curiously, though, while the Standard part of ArcTan[Dual[y,dy]/Dual[x,dx]] follows the expectation of ArcTan[y/x] and gives the same result for x negative and y positive as for x positive and y negative, the NonStandard part of ArcTan[Dual[y,dy]/Dual[x,dx]] distinguishes between these two cases and gives the correct results for the partial derivatives:
Pasted Graphic

This also applies when both x and y are negative. While the standard part gives the same result, incorrectly, as if both variables were positive, the NonStandard part correctly switches sign between the partial derivatives for the two cases, either both variables negative or both positive:
Pasted Graphic 1

In my computations for minimizing the mean squared error function, it is important to be able to distinguish between angles from different quadrants.

Therefore, I would like to ask you a) if my analysis presented above is correct and b) if so, do you have suggestions for how to use DualNumbers when angles between -Pi and +Pi need to be correctly identified?

Thanks for any advice you can give.

Rudolf

@SjoerdSmitWolfram
Copy link
Collaborator

Hi Rudolf. I just wanted to let you know I did see your comment, but I'm busy right now to really work on this. If you have a suggestion and/or sources for how the 2-arg form of ArcTan with duals should evaluate, please feel free to post it. I'm not quite sure I have a good suggestion for it off the top of my head.

@rudolfoldenbourg
Copy link
Author

Hi Sjoerd, I found a workaround by defining the function arcTanDual[x,y]:
image

The definition arcTanDual[x,y] works not only for DualNumbers x and y, but also if they are normal Reals.

Maybe something like this can be integrated more seamlessly into the paclet.

By the way, I was disappointed that in the new Mathematica version 14.0, your DualNumbers paclet was not yet integrated into the larger system. Maybe issues like the above still prevent that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants