SymPy: Can I safely differentiate atan2()?
Asked Answered
R

1

5

I would like to obtain a symbolic expression which is the derivative of atan2(y,x), where y and x are some expressions with a variable z. Can I safely assume that diff(atan2(y,x),z) gives me what I want?

In math.stackexchange.com there is a proof that atan2 is continuously differentialable in (-pi,pi), but is it in SymPy?

Reagent answered 5/9, 2018 at 2:48 Comment(2)
To start with, you can't call sympy.diff on an expression of two variables without telling it what you want to differentiate. Also, continuously differentiable for what in (-pi, pi)? Surely not x or y. Maybe it's continuously differentiable cutting atan on that range (which I think means the variable you're differentiating on is nonnegative and the other is nonzero?).Lorrianelorrie
@Lorrianelorrie atan2(y,x) is two argument function: by y I mean some expression, as in the case of x. You are right, I forgot the differentiation variable in diff!Reagent
M
8

The partial derivatives of atan2(y, x) with respect to x and y are computed by SymPy as

-y/(x**2 + y**2) 
 x/(x**2 + y**2)

and these expressions are continuous as long as x, y do not turn into zero at once. (Assuming real arguments x, y, of course - I don't think anyone puts complex numbers in atan2).

The above formulas are hardcoded here, so we can be very sure that SymPy will return them.

Margoriemargot answered 5/9, 2018 at 2:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.