I don't know if this question has been asked before, or if this is the right site to ask it. If not, let me know about a site where can I ask, please.

Problem: I want to create a block diagonal matrix with different size of blocks in GAP, for example with a block $1\times 1$ and a block $2\times 2$. I read the manual of GAP and I found the command "BlockMatrix" but I don't understand if it is possible to create such a matrix it with different sizes of blocks.

Thanks in advance!

  • $\begingroup$ The manual entry for BlockMatrix says "All matrices M(i,j) must have the same dimensions." So, you can't make a block matrix with blocks of different sizes with this command. $\endgroup$ Commented Mar 11, 2022 at 3:08
  • $\begingroup$ Right. So, is there another way to create such a matrix? I'd think that there is. $\endgroup$ Commented Mar 11, 2022 at 3:13

1 Answer 1


As long as the blocks are diagonal, you can use DirectSumMat with the matrices to be placed along the diagonal as arguments:

gap> m1:=[[1,2],[3,4]];;
gap> m2:=[[1,2,3],[4,5,6],[7,8,9]];;
gap> DirectSumMat(m1,m2);
[ [ 1, 2, 0, 0, 0 ], [ 3, 4, 0, 0, 0 ], [ 0, 0, 1, 2, 3 ], [ 0, 0, 4, 5, 6 ],
  [ 0, 0, 7, 8, 9 ] ]

If the blocks are not along the diagonal, you would have to build the matrix yourself.

(BlockMatrix is a special representation where blocks must have the same dimension, used mainly for representing induced representations)


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .