Mathematica has functions ArcCos, ArcSin, and ArcTan, but none of these does what I need, which is, given two real numbers a and b, at least one of them being nonzero, to find the angle x such that

{Cos[x], Sin[x]} == {a,b}/Sqrt[a^2+b^2].

Is there a simple way to build such a function? Thanks for any help.

  • 1
    $\begingroup$ There's a reason why I'm not called bobthemathematician, but how about rolling your own? Solve[{Cos[x] == a/Sqrt[a^2 + b^2], Sin[x] == b/Sqrt[a^2 + b^2]}, x] $\endgroup$ – bobthechemist Nov 12 '14 at 4:00
  • 8
    $\begingroup$ ArcTan[a, b] does what you want. $\endgroup$ – Rahul Nov 12 '14 at 4:10
  • $\begingroup$ ArcTan[a,b] is the best answer in terms of efficiency but was entered as a comment so it could not be accepted. The answer by HaoLiang and Kuba also works and provides good insight. $\endgroup$ – Soldalma Nov 12 '14 at 12:53

You can use this

Arg[#1 + I*#2] &[a, b]
  • $\begingroup$ How is this different from ArcTan[#1,#2]&[a,b]? $\endgroup$ – Ruslan Feb 14 '16 at 7:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.