Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

How does one multiply a list of matrices by a list of vectors, elementwise? For example, multiplying

A = {IdentityMatrix[2], 2*IdentityMatrix[2]}
x = {{1, 1}, {2, -2}}

should return

{{1, 1}, {4, -4}}

Neither Dot nor Times accomplishes this; both have the wrong dimensions. A cumbersome way would be

result = {{0, 0}, {0, 0}}
Do[result[[i]] = A[[i]].x[[i]], {i, 2}]

but surely there is a cleaner way.

share|improve this question
add comment

3 Answers

up vote 6 down vote accepted
  MapThread[Dot, {A, x}]  (* ? *)
share|improve this answer
add comment

Perhaps just:

Dot @@@ Transpose[{A, x}]
share|improve this answer
add comment

Following Belasarius in a somewhat more transparent fashion, you Apply[ ] the Dot function to A and x. The Transpose is used to get the A and x into a single list and the "1" causes the Apply to to work at the correct level.

 Apply[Dot, Transpose[{A, x}], 1]
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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