# Is atan2 in the base?

**URL:** <https://discourse.julialang.org/t/is-atan2-in-the-base/23764>\
**Category:** New to Julia\
**Created:** [May 2, 2019, 5:13am UTC](https://discourse.julialang.org/t/is-atan2-in-the-base/23764 "2019-05-02T05:13:59Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Colosus49](https://avatars.discourse-cdn.com/v4/letter/c/f17d59/32.png) [@Colosus49](https://discourse.julialang.org/u/Colosus49)\
**Post date:** [May 2, 2019, 5:13am UTC](https://discourse.julialang.org/t/is-atan2-in-the-base/23764/1 "2019-05-02T05:13:59Z")

</div>

is atan2 in the base? or is part of another package?

---

<div class="post-metadata">

**Author:** ![fredrikekre](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fredrikekre/32/1688_2.png) [@fredrikekre](https://discourse.julialang.org/u/fredrikekre)\
**Post date:** [May 2, 2019, 5:21am UTC](https://discourse.julialang.org/t/is-atan2-in-the-base/23764/2 "2019-05-02T05:21:16Z")

</div>

Are you looking for two-argument `atan`? [From the docs](https://docs.julialang.org/en/v1/base/math/#Base.atan-Tuple%7BNumber%7D):

```julia
  atan(y)
  atan(y, x)

  Compute the inverse tangent of y or y/x, respectively.

  For one argument, this is the angle in radians between the positive
  x-axis and the point (1, y), returning a value in the interval
  [-\pi/2, \pi/2].

  For two arguments, this is the angle in radians between the positive
  x-axis and the point (x, y), returning a value in the interval [-\pi, \pi].
  This corresponds to a standard
  atan2 (https://en.wikipedia.org/wiki/Atan2) function.

```

---

<div class="post-metadata">

**Author:** ![Colosus49](https://avatars.discourse-cdn.com/v4/letter/c/f17d59/32.png) [@Colosus49](https://discourse.julialang.org/u/Colosus49)\
**Post date:** [May 2, 2019, 5:48am UTC](https://discourse.julialang.org/t/is-atan2-in-the-base/23764/3 "2019-05-02T05:48:34Z")

</div>

Yes, I am aware of it. I am trying to get the angle of each element for a complex matrix (1024x1024). The results are bound to exceed the -pi/2 to pi/2 provided by atan. Atan2 should provide the -pi to pi range for the calculations I am performing.

I tried the atan(x,y) that comes with the base of Julia, but it cannot solve matrices. I get this error:  
RROR: MethodError: no method matching atan(::Array{Float64,2}, ::Array{Float64,2})  
Closest candidates are:  
atan(::AbstractArray{T,2} where T) at C:\cygwin\home\Administrator\buildbot\worker\package\_win64\build\usr\share\julia\stdlib\v1.1\LinearAlgebra\src\dense.jl:1013  
Stacktrace:  
[1] top-level scope at none:0

Posted the question in Github, and I was told that I should use atan2.(y,x). In this case they made the point that it should have a period at the end of “atan2.”. Also, they sent me here because this was a question of usage, not an issue.

I tried atan2(y,x) with single elements, or atan2.(y,x) with matrices and I get:  
ERROR: UndefVarError: atan2 not defined  
Stacktrace:  
[1] top-level scope at none:0

So I am to assume that I don’t have the correct package for atan2; I was misdirected; or there is problem with my version of Julia.

Thanks.

---

<div class="post-metadata">

**Author:** ![marius311](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/marius311/32/3953_2.png) [@marius311](https://discourse.julialang.org/u/marius311)\
**Post date:** [May 2, 2019, 5:54am UTC](https://discourse.julialang.org/t/is-atan2-in-the-base/23764/4 "2019-05-02T05:54:31Z")

</div>

Is `angle.(x)` what you’re looking for?

---

<div class="post-metadata">

**Author:** ![Colosus49](https://avatars.discourse-cdn.com/v4/letter/c/f17d59/32.png) [@Colosus49](https://discourse.julialang.org/u/Colosus49)\
**Post date:** [May 2, 2019, 6:01am UTC](https://discourse.julialang.org/t/is-atan2-in-the-base/23764/5 "2019-05-02T06:01:10Z")

</div>

Yes, that works. Thank you.

Is there some documentation where it is explained when to use the “.”?  
atan doesn’t need it to work on matrices, and some of the comments online were talking of “atan2” and “atan2.” which don’t work.

Any way, Thank you again.

---

<div class="post-metadata">

**Author:** ![Colosus49](https://avatars.discourse-cdn.com/v4/letter/c/f17d59/32.png) [@Colosus49](https://discourse.julialang.org/u/Colosus49)\
**Post date:** [May 2, 2019, 6:03am UTC](https://discourse.julialang.org/t/is-atan2-in-the-base/23764/6 "2019-05-02T06:03:08Z")

</div>

Thanks for the “angle.” one too, that works even better.

---

<div class="post-metadata">

**Author:** ![marius311](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/marius311/32/3953_2.png) [@marius311](https://discourse.julialang.org/u/marius311)\
**Post date:** [May 2, 2019, 6:08am UTC](https://discourse.julialang.org/t/is-atan2-in-the-base/23764/7 "2019-05-02T06:08:24Z")

</div>

Check out [Multi-dimensional Arrays · The Julia Language](https://docs.julialang.org/en/v1/manual/arrays/index.html#Broadcasting-1)

Edit: this is even better [Functions · The Julia Language](https://docs.julialang.org/en/v1/manual/functions/#man-vectorized-1)

Short answer is that the dot “broadcasts” any function across elements of the arguments, kind of like auto-vectorizing it. Note btw that `atan(::Matrix)` is _not_ computing element-wise arc tangent. If you type `?atan` to get the docs you’ll see it explained that its doing the “the inverse matrix tangent of a square matrix A.”

---

<div class="post-metadata">

**Author:** ![mbauman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mbauman/32/31082_2.png) [@mbauman](https://discourse.julialang.org/u/mbauman)\
**Post date:** [May 2, 2019, 6:14am UTC](https://discourse.julialang.org/t/is-atan2-in-the-base/23764/8 "2019-05-02T06:14:56Z")

</div>

Shorter answer is that the `.` applies functions “pointwise” or elementwise. Instead of acting on a matrix as a whole, it acts on each individual element. There’s more to broadcast, but with 1-argument functions that’s it.

A great example is this `square` function:

```julia
julia> square(x) = x*x
square (generic function with 1 method)

julia> square([1 2; 3 4])
2×2 Array{Int64,2}:
  7 10
 15 22

julia> square.([1 2; 3 4])
2×2 Array{Int64,2}:
 1 4
 9 16

```

If you call `square(A)` directly with a matrix, it’ll compute the matrix-matrix product. If you call `square.(A)`, then it’ll compute the squares of each element individually.

---

<div class="post-metadata">

**Author:** ![Colosus49](https://avatars.discourse-cdn.com/v4/letter/c/f17d59/32.png) [@Colosus49](https://discourse.julialang.org/u/Colosus49)\
**Post date:** [May 2, 2019, 6:36am UTC](https://discourse.julialang.org/t/is-atan2-in-the-base/23764/9 "2019-05-02T06:36:10Z")

</div>

Great. Thanks. I’ll have to try all of those, and need to read more.

Thanks to both of you, you had been really helpful.
