Ask Your Question
1

coercion of matrix of matrices to single matrix

asked 2023-10-15 00:17:34 +0200

QMeqGR gravatar image

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 flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2023-10-15 01:45:07 +0200

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]
edit flag offensive delete link more

Your Answer

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

Add Answer

Question Tools

1 follower

Stats

Asked: 2023-10-15 00:17:34 +0200

Seen: 74 times

Last updated: Oct 15 '23