0
$\begingroup$

For most other functions, passing in a list of arguments will return a list of results. E.g.

t = Range[0, 10];
m = N[Sin[t]]

returns

{0., 0.841471, 0.909297, 0.14112, -0.756802, -0.958924, -0.279415,
0.656987, 0.989358, 0.412118, -0.544021}

I would like a list of rotation matrices for each element in t like this

matList = RotationMatrix[t]

but it returns an error. Is there a way I can do this?

Thanks!

$\endgroup$
  • $\begingroup$ Print[{Attributes[Sin], Attributes[RotationMatrix]} ];(* then you need*) RotationMatrix /@ Range@10 $\endgroup$ – Dr. belisarius Feb 18 '15 at 0:31
  • $\begingroup$ RotationMatrix does not have attribute Listable. So map it over the list... $\endgroup$ – ciao Feb 18 '15 at 0:31
  • $\begingroup$ Indeed RotationMatrix is not Listable, in part because the function can take a list of two vectors as arguments to compute the rotation matrix that takes vector 1 to vector 2. $\endgroup$ – David G. Stork Feb 18 '15 at 0:50
3
$\begingroup$

RotationMatrix is not Listable

Attributes[RotationMatrix]
(* {Protected, ReadProtected} *)

So you have to use Map (or Table) here

matList = RotationMatrix /@ t
(* {{{1, 0}, {0, 1}}, {{Cos[1], -Sin[1]}, {Sin[1], Cos[1]}}, ...} *)

You can define custom listable function like this

r[t_] := RotationMatrix[t]
SetAttributes[r, Listable]

r[t]
(* {{{1, 0}, {0, 1}}, {{Cos[1], -Sin[1]}, {Sin[1], Cos[1]}}, ... } *)

Yet another approach is to calculate the rotation matrix analytically. It contains Sin and Cos which are Listable. You can effectively do it with Block

Block[{t}, RotationMatrix[t]]
(* {{{1, Cos[1], ...}, {0, -Sin[1], ...}}, {{0, Sin[1], ...}, {1, Cos[1], ...}}} *)

Note the another order of dimensions.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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