[Numpy-discussion] arctan2 with complex args

David Goldsmith David.L.Goldsmith@noaa....
Mon Apr 30 09:01:03 CDT 2007


lorenzo bolla wrote:
> me!
> I have two cases.
>
>    1. I need that arctan2(1+0.00000001j,1-0.000001j) gives something
>       close to arctan2(1,1): any decent analytic prolungation will do!
>
This is the foreseeable use case described by Anne.

In any event, I stand not only corrected, but embarrassed (for numpy):

    Python 2.5 (r25:51918, Sep 19 2006, 08:49:13)
    [GCC 4.0.1 (Apple Computer, Inc. build 5341)] on darwin
    Type "help", "copyright", "credits" or "license" for more information.
     >>> import numpy as N
     >>> complex(0,1)
    1j
     >>> N.arctan(1)
    0.78539816339744828
     >>> N.arctan(complex(0,1))
    Warning: invalid value encountered in arctan
    (nannanj)

I agree that arctan should be implemented for _at least_ *one* complex 
argument...

DG
>
>    1. if someone of you is familiar with electromagnetic problems, in
>       particular with Snell's law, will recognize that in case of
>       total internal reflection
>       <http://en.wikipedia.org/wiki/Total_internal_reflection> the
>       wavevector tangential to the interface is real, while the normal
>       one is purely imaginary: hence the angle of diffraction is still
>       given by arctan2(k_tangent, k_normal), that, as in Matlab or
>       Octave, should give pi/2 (that physically means no propagation
>       -- total internal reflection, as said).
>
> L.
>
> On 4/30/07, *Anne Archibald* <peridot.faceted@gmail.com 
> <mailto:peridot.faceted@gmail.com>> wrote:
>
>     On 29/04/07, David Goldsmith <David.L.Goldsmith@noaa.gov
>     <mailto:David.L.Goldsmith@noaa.gov>> wrote:
>     > Far be it from me to challenge the mighty Wolfram, but I'm not
>     sure that
>     > using the *formula* for calculating the arctan of a *single*
>     complex
>     > argument from its real and imaginary parts makes any sense if x
>     and/or y
>     > are themselves complex (in particular, does Lim(formula), as the
>     > imaginary part of complex x and/or y approaches zero, approach
>     > arctan2(realpart(x), realpart(y)?) - without going to the trouble to
>     > determine it one way or another, I'd be surprised if "their"
>     > continuation of the arctan2 function from RxR to CxC is (a. e.)
>     > continuous (not that I know for sure that "mine" is...).
>
>     Well, yes, in fact, theirs is continuous, and in fact analytic, except
>     along the branch cuts (which they describe). Formulas almost always
>     yield continuous functions apart from easy-to-recognize cases. (This
>     can be made into a specific theorem if you're determined.)
>
>     Their formula is a pretty reasonable choice, given that it's not at
>     all clear what arctan2 should mean for complex arguments. But for
>     numpy it's tempting to simply throw an exception (which would catch
>     quite a few programmer errors that would otherwise manifest as
>     nonsense numbers). Still, I suppose defining it on the complex
>     numbers
>     in a way that is continuous close to the real plane allows people to
>     put in almost-real complex numbers and get out pretty much the answer
>     they expect. Does anyone have an application for which they need
>     arctan2 of, say, (1+i,1-i)?
>
>     Anne
>     _______________________________________________
>     Numpy-discussion mailing list
>     Numpy-discussion@scipy.org <mailto:Numpy-discussion@scipy.org>
>     http://projects.scipy.org/mailman/listinfo/numpy-discussion
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> Numpy-discussion mailing list
> Numpy-discussion@scipy.org
> http://projects.scipy.org/mailman/listinfo/numpy-discussion
>   



More information about the Numpy-discussion mailing list