1

I have a matrix like this (myb1):

myb1 matrix output

I would like to get the matrix multiplication of each of the submatrix to itself. For example the first $2\times2$ matrix $\begin{bmatrix}1 & 2\\1 & 2\end{bmatrix}$ should be multiplied by itself and answer of res2[[1, 1]] be $\begin{bmatrix}3 & 6\\3 & 6\end{bmatrix}$ and so on.

I tried: for loop (in the picture) and didn't help

Direct Mathematica code: myb1.myb1 and it didn't work out either

Mathematica Code

myb1[[1, 1]] = {{1, 2}, {1, 2}}

myb1[[1, 2]] = {{2, 3}, {3, 4}}

myb1[[2, 1]] = {{5, 2}, {8, 2}}

myb1[[2, 2]] = {{1, 2}, {1, 2}}

For[i = 1, i <= 2, i++,

 For[j = 1, j <= 2, j++,

  res2 = myb1[[i, j]].myb1[[i, j]];

  ]

 ]
J. M.'s missing motivation
  • 124,525
  • 11
  • 401
  • 574
sc3339
  • 23
  • 6
  • Here is a link to a FAQ post that explains why it's typically a bad idea to use MatrixForm, no matter how alluring its nicely formatted output might be: (18393). – MarcoB Jul 04 '15 at 02:55
  • @MarcoB: removed unwanted edits to abate duplication – sc3339 Jul 04 '15 at 03:16
  • 2
    You will still want to avoid using MatrixForm as you are showing. If you absolutely need to have pretty-printed matrices, then at least use: (myb1 = {{1, 2}, {1, 2}}) // MatrixForm;. Note the () brackets: they change the order of execution so that the variable myb1 is assigned the "raw" matrix, before the MatrixForm is evaluated. – MarcoB Jul 04 '15 at 04:04
  • 1
    to clarify here, MatrixForm is a display function. it's used to show your results as a matrix, but is not used during calculations. you don't need to tell Mathematica "hey this is a matrix" because any rectangular list of lists is as good a matrix as you need. for example Det[{{a, 1}, {Graphics[Disk[]], d}}] will give an answer. this is a deliberate design feature. in particular, it means that all the functions you use for dealing with lists (such as Reverse) can also be used directly on matrices... and vice versa. – amr Jul 04 '15 at 05:14
  • Thank you again for your response @MarcoB , removed matrix form from code as well – sc3339 Jul 05 '15 at 05:26

1 Answers1

5

For the love of this fine site, please post copyable code along with accompanying images the next time!

Anyway:

myb1 = {{{{1, 2}, {1, 2}}, {{2, 3}, {3, 4}}},
        {{{5, 2}, {8, 2}}, {{1, 2}, {1, 2}}}};

Map[MatrixPower[#, 2] &, myb1, {2}]
   {{{{3, 6}, {3, 6}}, {{13, 18}, {18, 25}}},
    {{{41, 14}, {56, 20}}, {{3, 6}, {3, 6}}}}

Map[#.# &, myb1, {2}]
   {{{{3, 6}, {3, 6}}, {{13, 18}, {18, 25}}},
    {{{41, 14}, {56, 20}}, {{3, 6}, {3, 6}}}}
J. M.'s missing motivation
  • 124,525
  • 11
  • 401
  • 574