0
$\begingroup$

I have list of number pairs

l = {{1, 0}, {1, 1}, {0, 1}, {-1, 1}, {-1, 0}, {-1, -1}, {0, -1}}

of which I want to take the ArcTan

ArcTan[l]
{{π/4, 0}, {π/4, π/4}, {0, π/4}, {-(π/4), π/4}, {-(π/4), 0}, {-(π/4), -(π/4)}, {0, -(π/4)}}

This is not the desired answer because the curly brackets around the number pairs.

I solved it with

f[{x_, y_}] := ArcTan[x, y] 
f/@ l
{0, π/4, π/2, (3 π)/4, π, -((3 π)/4), -(π/2)}     

Is this the way to do this?

$\endgroup$
1
  • 11
    $\begingroup$ Use ArcTan @@@ l which is shorthand for Apply[ArcTan, l, {1}] $\endgroup$
    – Bob Hanlon
    Jul 21, 2020 at 15:37

1 Answer 1

2
$\begingroup$

Since ArcTan is Listable,

ArcTan[{a,b,c}]

is equivalent to

{ArcTan[a], ArcTan[b],ArcTan[c]}

and

ArcTan[{{p, q}, {u, v}, {x, y}}]

is equivalent to

{{ArcTan[p], ArcTan[q]}, {ArcTan[u], ArcTan[v]}, {ArcTan[x], ArcTan[y]}}

In Order to get the right result, ArcTan need to act directly on 1,0 and 1,1 etc.

ArcTan@@@{{1, 0}, {1, 1}, {0, 1}, {-1, 1}, {-1, 0}, {-1, -1}, {0, -1}}
$\endgroup$

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