Skip to main content
2 of 4
Changing question name to emphasize that it's merely
Harold
  • 1k
  • 8
  • 16

Why don't * and ^ work as I'd expect on matrices?

For example, this input...

{{1, 2}, {3, 4}}*{{1, 2}, {3, 4}}

produces this output...

{{1, 4}, {9, 16}}

and this input...

{{1, 2}, {3, 4}}^2

produces the same...

{{1, 4}, {9, 16}}

What I want in both cases is...

{{7, 10}, {15, 22}}

I think I know what's going on here. Mathematica doesn't seem to be discriminating between lists of lists, and matrices, and the * and ^ operators are just threading over the lists.

I've found . and MatrixPower which do what I think * and ^ should.

But the question still remains, is this confusing (to at least me) behavior of * and ^ by design, and what benefit does it confer?

Harold
  • 1k
  • 8
  • 16