In Mathematica there are two different forms for the arctangent (inverse tangent), namely
ArcTan[x,y]
which gives the arc tangent of $y/x$, taking into account which quadrant the point $(x,y)$ is in, and
ArcTan[z]
which gives the arc tangent $\tan^{-1}(z)$ of the complex number $z$.
I am not sure about the exact conversion rule, but as far as I understand it is not simply
ArcTan[z] == ArcTan[x+I y] == ArcTan[x,y]
How do I restrict Mathematica to use only one of the two forms for ArcTan
, or convert between the two?
EDIT
Maybe I should elucidate on the problem at hand.
I am trying to solve the equation
$$
a \cos(x) + b \sin(x) = c
$$
which can be done with the Weierstrass substitution to yield
$$
x_{\pm} = 2 \arctan\left[ \frac{b \pm \sqrt{a^2+b^2 - c^2}}{a+c}\right]
$$
which is of the type ArcTan[z]
. But if instead I use Mathematica
Solve[a Cos[x] + b Sin[x] == c, x]
Then I get an ugly expression of the type ArcTan[x,y]
:
$$ \arctan\left[\frac{a c-\sqrt{a^2 b^2+b^4-b^2 c^2}}{a^2+b^2},\frac{\frac{a \sqrt{-b^2 \left(-a^2-b^2+c^2\right)}}{a^2+b^2}-\frac{a^2 c}{a^2+b^2}+c}{b}\right] $$
How do I tell Mathematica to convert this expression into an ArcTan[z]
or vice versa?
(I purposely neglected the periodicity of the solutions.)
EDIT 2
I just saw, that Reduce
yields an ArcTan[z]
. Where is the logic behind this?
ToMatlab
seems to be totally off, asArcTan[x,y] //ToMatlab
yieldsatan(x,y)
, but should beatan2(y,x)
. $\endgroup$ToMatlab
is not a perfect package, and you'll find a lot of other errors, if you use it often enough. Re: "How do I restrict Mathematica to use only one of the two forms" – well, you are the one calling the function, right? Mathematica doesn't accidentally switch from a one argument version to two or vice versa unless you explicitly say so. $\endgroup$