[R] atan2(1,1i)

Prof Brian Ripley ripley at stats.ox.ac.uk
Wed Mar 29 10:00:23 CEST 2006


On Wed, 29 Mar 2006, Robin Hankin wrote:

> Hi guys
>
> perhaps my original message wasn't so clear.
>
> My point was that the documentation is inconsistent with the
> function.

I think it is _your reading_ of the documentation that is inconsistent.
An equally plausible reading is that both x and y must be numeric or 
complex.

> How to remedy this?
>
> (i) add a line to Trig.Rd along the lines of "atan2() will not work
> if the first argument
> is real and the second argument complex"
>
> or
> (ii) Modify atan2() so that it coerces the first argument to a
> complex if necessary.
>
>
> I'd prefer option (ii) but can't see a quick fix.

Really?  It's a one-line change.

BTW, this *really* is an R-devel topic, so please try to use the
appropriate list.  Suggestions for changes to R get lost in the torrent of 
R-help extremely easily.

And only the designers can say

'but atan2 wasn't originally designed for complex arguments.'

but the code suggests otherwise.

>
>
> rksh
>
>
>
>
> On 28 Mar 2006, at 19:52, Jeff Newmiller wrote:
>
>> Robin Hankin wrote:
>>> Hi
>>>
>>> ?atan2 says that atan2(y,x)=atan(y/x) for x and y numeric or complex
>>> vectors.
>>>
>>> Well, I would expect atan2(1,1i) to be equal to atan(-1i), but
>>>
>>>> atan2(1,1i)
>>> Error in atan2(y, x) : Non-numeric argument to mathematical function
>>
>> Ravi Varadhan pointed out that you need to make both arguments complex
>> to address the error message you obtained... but atan2 wasn't
>> originally
>> designed for complex arguments. I suspect that what you really want is
>> to use the Arg function:
>>
>>> Arg(1/1i)
>> [1] -1.570796
>>
>> --
>
>
> --
> Robin Hankin
> Uncertainty Analyst
> National Oceanography Centre, Southampton
> European Way, Southampton SO14 3ZH, UK
>  tel  023-8059-7743
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595




More information about the R-help mailing list