MathGroup Archive 2006

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Vector operations,

I presume you used:


Let's take, for example:

   mat = RotationMatrix2D[Pi/3];

If you had wanted to rotate a single vector, say


by that matrix, you would use the dot product:


Now the dot infix notation is an abbreviation for the actual function 
involved, namely, Dot.  That is, the expression "mat.v" is shorthand for:

   Dot[mat, v]

So you have a two-argument function Dot that you want to use with a 
fixed first argument (mat) but various second arguments.  The standard 
way to handle this in Mathematica is to form a pure function like this:

   Dot[mat, #]&

(That's a nameless function that dots things with mat.)

Finally, to cause this function to act upon each of the vectors in a 
list of vectors such as....

   vectors = {{1/2, 1/2}, {1, 0}, {0, 1}, {0, 0}};

use the function Map:

   Map[Dot[mat, #]&, vectors]

The result will be the desired list of rotated vectors.

One more thing, to avoid the nested brackets, you can use the 
abbreviation func /@ lis instead of Map[func, lis].  With this 
abbreviation, then, the desired expression to rotate all the vectors is:

   Dot[mat, #]& /@ vectors

Of course if you're going to be repeatedly rotating vectors by the same 
angle, you may want to define a function to do it:

   rot[vec_] := mat.vec

Then to rotate all the vectors in the list at once:

   Map[rot, vectors]

or, abbreviated:

   rot /@ vectors

Isn't that nice!

mickey wrote:
> Hi,
> I have a list of vectors such as
> {{1/2, 1/2}, {1, 0}, {0, 1}, {0, 0}}
> I want to rotate them all by the same angle. Right now, what I do is 
> multiply each by RotationMatrix2D[t] and iterate over the list. Is there 
> a more efficient way to do this?
> Thanks,
> -M

Murray Eisenberg                     murray at
Mathematics & Statistics Dept.
Lederle Graduate Research Tower      phone 413 549-1020 (H)
University of Massachusetts                413 545-2859 (W)
710 North Pleasant Street            fax   413 545-1801
Amherst, MA 01003-9305

  • Prev by Date: Re: Re: equation question
  • Next by Date: RE: Re: Re: distance function
  • Previous by thread: Vector operations,
  • Next by thread: Re: Vector operations,