5
$\begingroup$

I have a $(2 \times 2)$ matrix whose elements are themselves $(2 \times 2)$ matrices (i.e., a partitioned matrix), e.g: $$ M = \begin{pmatrix} A & B \\ C & D \end{pmatrix}, \quad \quad \text{with } A,B,C,D \in \text{Mat}_{2 \times 2}. $$ Problem: I want to compute some things with this matrix, in particular an expression for $M^{n}$, I have tried using MatrixPower[M, n] in Mathematica but this does not work, (the error message says that the argument at position 1 is not a non-empty square matrix). If I pretend that $A,B,C,D$ are scalars then Mathematica will automatically assume multiplicative commutativity when computing powers of $M$.

Additional info: Furthermore, matrix multiplication does not work, if I try $M.M$ then I expect to obtain a result which looks like: $$ \begin{pmatrix} A.A + B.C & A.B+B.D \\ C.A+D.C &C.B+D.D \end{pmatrix}, $$ however, instead, I obtain a result in which the entries of $M.M$ are $(2 \times 2)$ matrices of $(2 \times 2)$ matrices (a bit complicated to explain).

Many thanks if someone can tell me how to compute matrix powers of a matrix whose elements are themselves matrices.

$\endgroup$
3
  • 2
    $\begingroup$ It looks to me that your expected result is incorrect. Could you check? $\endgroup$ Commented Oct 6, 2015 at 12:25
  • $\begingroup$ Apologies, it is now amended. $\endgroup$
    – analytic
    Commented Oct 6, 2015 at 12:41
  • $\begingroup$ Similar problem/question is discussed here: mathematica.stackexchange.com/questions/7902/… "Matrix multiplication in Block Form symbolic calculation by Mathematica". $\endgroup$ Commented Oct 9, 2015 at 13:34

3 Answers 3

9
$\begingroup$

We can use the symbolic representation of the block matrix and perform the matrix operations with Inner and NonCommutativeMultiply. At the end we replace the matrix blocks with numeric or symbolic matrices. Below is an example.

The package and articles at "Noncommutative Algebra Package and Systems" might be of interest if these kind of manipulations are going to be done often and in more general form.

Here is a block matrix in symbolic form:

blockMat = {{A11, A12}, {A21, A22}};
MatrixForm[blockMat]

Here is the matrix multiplication using Inner and NonCommutativeMultiply.

blockMat2 = 
  Outer[Inner[NonCommutativeMultiply, #1, #2, Plus] &, blockMat, 
   Transpose[blockMat], 1];
MatrixForm[blockMat2, 1]

Note that the use of Inner directly corresponds to the block-matrix row-by-column multiplication.

This replaces the symbols for the matrix blocks with numerical matrices:

nBlockMat2 = 
  blockMat2 /. {A11 -> RandomReal[{0, 1}, {2, 2}], 
    A12 -> RandomReal[{10, 11}, {2, 2}], 
    A21 -> RandomReal[{100, 101}, {2, 2}], 
    A22 -> RandomReal[{1000, 1001}, {2, 2}]};

This command makes the sub-matrix multiplications:

MatrixForm[nBlockMat2 /. NonCommutativeMultiply -> Dot]

The above result with ArrayFlatten applied to it:

MatrixForm[ArrayFlatten[nBlockMat2 /. NonCommutativeMultiply -> Dot]]

Here is an image of the above in a Mathematica session:

enter image description here

$\endgroup$
3
$\begingroup$

I have realised it is a simple answer, I can just regard $M$ as a $(4 \times 4)$ matrix, eg. \begin{eqnarray} M = \left(\begin{array}{cccc} a_{1} & a_{2} & b_{1} & b_{2} \\ a_{3} & a_{4} & b_{3} & b_{4} \\ c_{1} & c_{2} & d_{1} & d_{2} \\ c_{3} & c_{4} & d_{3} & d_{4} \end{array} \right), \end{eqnarray} now $M.M$ in Mathematica gives the result which is correctly of the form, \begin{eqnarray} \left(\begin{array}{cc} A.A+B.C & A.B+B.D \\ C.A+D.C & C.B+D.D \end{array} \right) \quad \quad \quad \quad (1) \end{eqnarray} (with the interpretation that the $(2 \times 2)$ blocks of $M.M$ are the elements of (1).)

Thanks for all comments.

$\endgroup$
1
  • 4
    $\begingroup$ In that regard: have you seen ArrayFlatten[]? $\endgroup$ Commented Oct 6, 2015 at 13:26
0
$\begingroup$

enter image description here

the only way to do that is using ArrayFlatten

$\endgroup$
1
  • 1
    $\begingroup$ Please post code in Mathematica format rather than images. Also, note that your answer is much the same as an earlier comment. $\endgroup$
    – bbgodfrey
    Commented Aug 30, 2018 at 20:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.