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.

So I have a set of 15 $4\times 4$ matrices which I call $X_i, (i=1,2..15)$ and a set of 6 $4\times 4$ matrices which I call $y_j, (j=1,2...6)$. Now I have to calculate $(X_i y_j)-(y_j X_i^*)$ for different values of $i$ and $j$, where $*$ stands for Complex conjugate. Is there a simple command (with perhaps loops) in mathematica using which I can calculate all the 90 results instead of multiplying these matrices individually 90 times?

share|improve this question
Have a look at Outer. –  b.gatessucks Dec 3 '12 at 8:29
Try Outer[#1.#2 - #2.Conjugate[#1] &, X, y] –  E.O. Dec 3 '12 at 9:08

1 Answer 1

Define some matrices.

Xs = RandomInteger[{1, 4}, {2, 4, 4}];
ys = RandomInteger[{1, 4}, {3, 4, 4}];

Use Outer applied to the indices to produce your derived matrices:

Outer[#1.#2 - #2.Conjugate@#1 &, Xs, ys]
, 1]

Flatten provides your result matrices in a single level list.

Or to follow your naming convention of variable names with subscripts:

Define the number of Xs and ys:

numXs = 2;
numys = 3;

  Subscript[X, #1].Subscript[y, #2] - 
    Subscript[y, #2].Conjugate@Subscript[X, #1] &, Range@numXs, 
  Range@numys], 1]
share|improve this answer

Your Answer


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.