Re: Possible Bug in ArcTan ?
- To: mathgroup at smc.vnet.net
- Subject: [mg64853] Re: Possible Bug in ArcTan ?
- From: "David W. Cantrell" <DWCantrell at sigmaxi.org>
- Date: Sun, 5 Mar 2006 03:19:46 -0500 (EST)
- References: <email@example.com> <firstname.lastname@example.org> <email@example.com> <firstname.lastname@example.org>
- Sender: owner-wri-mathgroup at wolfram.com
Paul Abbott <paul at physics.uwa.edu.au> wrote: > In article <du8are$fp7$1 at smc.vnet.net>, > "David W. Cantrell" <DWCantrell at sigmaxi.org> wrote: > > > "Jens-Peer Kuska" <kuska at informatik.uni-leipzig.de> wrote: > > > Hi, > > > > > > why can ArcTan have two arguments ArcTan[x,y] > > > > As the Help Browser says, > > "taking into account which quadrant the point (x,y) is in." > > > > For example, suppose you want to convert -2 + I to polar form, > > r*E^(I*theta). One can't simply say theta = ArcTan[1/-2]. The range of > > the single-argument ArcTan is [-Pi/2, Pi/2], i.e., fourth and first > > quadrants, while our point (-2, 1) is in the third quadrant. But we can > > conveniently say theta = ArcTan[-2, 1]. > > Or we can say theta = 2 ArcTan[1/(Sqrt-2)] (see below). > > > Note: Some other languages implement the two-argument form under the > > name ATAN2. Furthermore, the order of the two arguments is often > > backwards compared to Mathematica's, that is, ATAN2(y,x). > > There is another way that avoids the two-argument form altogether. Yes, there are alternative ways. One can indeed write something equivalent to the two-argument form using just standard trig functions etc., but those ways typically involve considering some special case(s). See below. > Using the half-angle formula for tan, > > Simplify[Tan[t/2] == Sin[t]/(Cos[t] + 1)] > > True > > then in polar coordinates, x=r Cos[t], y=r Sin[t], r=Sqrt[x^2+y^2], > > Tan[t/2] == y/(x+r) ==> t == 2 ArcTan[y/(x+Sqrt[x^2+y^2])] > > This formula is also valid when x == 0, whereas ArcTan[y/x] is > problematic there (ArcTan[0,y] is ok, of course). t == 2 ArcTan[y/(x+Sqrt[x^2+y^2])] fails if y is zero and x is negative, and so that case would have to be considered separately. Of course, ArcTan[x,y] does not fail in such a case. Cheers, David