       Re: Vector operations,

• To: mathgroup at smc.vnet.net
• Subject: [mg70015] Re: Vector operations,
• From: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>
• Date: Sat, 30 Sep 2006 05:12:46 -0400 (EDT)
• Organization: The Open University, Milton Keynes, UK
• References: <efitqn\$lu4\$1@smc.vnet.net>

```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
>

The fastest computation is the dot product of the list of vectors with
components given is machine-precision numbers over the rotation matrix
(see In).

In:=
Needs["Geometry`Rotations`"]

In:=
(* Here we use exact arithmetic *)

In:=
m = RotationMatrix2D[Pi/4]

Out=
{{1/Sqrt, 1/Sqrt}, {-(1/Sqrt), 1/Sqrt}}

In:=
(* We generate 100,000 2-dimensional vectors *)

In:=
vecs = Partition[Range[1, 200000], 2];

In:=
t1 = Timing[s1 = (Rotate2D[#1, -(Pi/4)] & ) /@
vecs; ][]

Out=
11.735 Second

In:=
t2 = Timing[s2 = vecs . m; ][]

Out=
5.718 Second

In:=
(* Now we switch to hardware-precision arithmetic *)

In:=
vecs = N[vecs];
theta = N[-(Pi/4)];
m = N[m];

In:=
t3 = Timing[s3 = (Rotate2D[#1, theta] & ) /@ vecs; ][[
1]]

Out=
2.297 Second

In:=
t4 = Timing[s4 = vecs . m; ][]

Out=
0.015 Second

In:=
Count[Chop[s3 - s4], {0, 0}]

Out=
100000

In:=
Count[Chop[s1 - s4], {0, 0}]

Out=
100000

In:=
s1 == s2

Out=
True

In:=
t1/t4

Out=
782.333

Regards,
Jean-Marc

```

• Prev by Date: HoldPattern question
• Next by Date: Input, output troubles me ...
• Previous by thread: Re: Vector operations,
• Next by thread: [RESEND] How to tell Mathematica to use hardware floating point aithmetics