1
$\begingroup$

I have one vector v1 and one list of vectors v2. I want to find the angle between them (see below):

v1 = {1, 0, 0};
v2 = {{0, 0, 1}, {1, 0, 0}}; 

VectorAngle[v1, v2]

How can I do that?

$\endgroup$
  • 4
    $\begingroup$ Look up Map and Function in the documentation. $\endgroup$ – Szabolcs Apr 26 '18 at 16:16
3
$\begingroup$

As Szabolcs states you need to learn about Map and Function. These are very powerful and enable you to quickly calculate a list of values. Here I am using map. The # is a slot and the & makes a function.

v1 = {1, 0, 0};
v2 = {{0, 0, 1}, {1, 0, 0}};
VectorAngle[v1, #] & /@ v2

(* {π/2, 0} *)

For fun let's make 50 vectors then plot them

v2 = RandomReal[{-1, 1}, {50, 3}];
Graphics3D[{Arrow[{{0, 0, 0}, #}] & /@ v2}]

Mathematica graphics

Here are all their angles

ListPlot[VectorAngle[v1, #] & /@ v2]

Mathematica graphics

Have fun learning Mathematica.

$\endgroup$
  • $\begingroup$ Wow...Thanks a lot for your wonderful explanation!! $\endgroup$ – Bikash Apr 26 '18 at 17:52

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