# coercion of matrix of matrices to single matrix

I have a need to construct matrices like the following:

A simple 2x2 matrix m1 = matrix([[a,b],[c,d]])

Then I need to make larger matrices out of them, as in M1 = matrix([[m1,0],[0,1]])

Big M1 has parent: mat2x2(mat2x2(SR)). However, to manipulate the matrix and do matrix x matrix multiplication I need this to be mat4x4(SR).

How can I do this?

edit retag close merge delete

Sort by ยป oldest newest most voted

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]

more

Please start posting anonymously - your entry will be published after you log in or create a new account.