Skip to main content
Post Closed as "Not suitable for this site" by corey979, rhermans, Henrik Schumacher, m_goldberg, halirutan
edited tags
Source Link

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. MathematicaMathematica 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?

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?

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?

edited title
Link

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

Changing question name to emphasize that it's merely
Link
Harold
  • 1k
  • 8
  • 16

Why dodon't * and ^ do the wrong thing forwork as I'd expect on matrices?

Source Link
Harold
  • 1k
  • 8
  • 16
Loading