Ask Your Question

Revision history [back]

You can use the block_matrix function:

sage: M = block_matrix([[m1,0],[zero_matrix(2), identity_matrix(2)]])
sage: M
[a b|0 0]
[c d|0 0]
[---+---]
[0 0|1 0]
[0 0|0 1]
sage: type(M)
<class 'sage.matrix.matrix_symbolic_dense.Matrix_symbolic_dense'>
sage: parent(M)
Full MatrixSpace of 4 by 4 dense matrices over Symbolic Ring

For this particular example, block_diagonal_matrix would also work. With either function, you can omit the subdivisions by passing subdivide=False when calling the function:

sage: M = block_diagonal_matrix(m1, identity_matrix(2), subdivide=False)
sage: M
[a b 0 0]
[c d 0 0]
[0 0 1 0]
[0 0 0 1]