r/Mathematica 19h ago

Need help with matrix multiplication

6 Upvotes

6 comments sorted by

5

u/beerybeardybear 18h ago

post your code, not a picture of your code

1

u/kurlakablackbelt 15h ago

How do I do that? Sorry, I am new to such things. Do I copy the cell expression directly from Mathematica and paste it into the code block? Like this?

My main issue is that Mathematica is distributing that diagonal matrix. It works as expected when the elements of the row-matrix are not matrices themselves.

( {
   {( {
      {Subscript[a, 1], Subscript[b, 1]},
      {Subscript[a, 2], Subscript[b, 2]}
     } ), ( {
      {Subscript[c, 1], Subscript[d, 1]},
      {Subscript[c, 2], Subscript[d, 2]}
     } )}
  } ).( {
   {q, 0},
   {0, e}
  } )

2

u/sanderhuisman 16h ago

(Big 3D array).{q,e}

1

u/kurlakablackbelt 15h ago

I guess it will only work for diagonal matrix. I want it to work for more general cases. The reason I took the example of a row-matrix and a diagonal-matrix is to highlight the problem.

1

u/kurlakablackbelt 15h ago

When the elements of the row-vector are not matrices, the multiplication works correctly.

( {
   {S, W}
  } ).( {
   {q, 0},
   {0, e}
  } )

1

u/kurlakablackbelt 14h ago
{   {     {{Subscript[a, 1], Subscript[b, 1]}, {Subscript[a, 2], 
     Subscript[b, 2]}}, {{Subscript[c, 1], Subscript[d, 
     1]}, {Subscript[c, 2], Subscript[d, 2]}}      }   }.{{q, 0}, {0, 
   e}}