Determinant of block matrices

I need to calculate the determinant of a symbolic 4x4 matrix M, where each cell itself is a matrix itself.

Is that possible?

I did a beginner's check, and it did not seem to work:

mq=matrix(SR, 2, 2, 'a b c d'.split(' '))
MQ=matrix(SR, 2, 2, [mq, mq, mq, mq])
MQ.det()

Traceback (click to the left of this block for traceback)
...
TypeError: mutable matrices are unhashable

edit retag close merge delete

Hey, are you from Germany?

( 2013-11-24 08:08:14 +0100 )edit

Sort by » oldest newest most voted

You are not defining a block matrix, but a 2 by 2 matrix whose entries are 2 by 2 martices over the symbolic ring. Indeed:

sage: MQ.parent()
Full MatrixSpace of 2 by 2 dense matrices over Symbolic Ring


Moreover, there is a kind of contradiction, since you ask the base ring to be SR but your entries are in the set of 2 by 2 martices over SR. If you remove this contradiction, you get:

sage: MQ=matrix(2, 2, [mq, mq, mq, mq])
sage: MQ.parent()
Full MatrixSpace of 2 by 2 dense matrices over Full MatrixSpace of 2 by 2 dense matrices over Symbolic Ring
sage: MQ.det()
[0 0]
[0 0]


To define a block matrix (so that sage understands that it is a 4 by 4 matrix over SR), you should do:

sage: MQ=matrix.block(2,2,[mq, mq, mq, mq])
sage: MQ
[a b|a b]
[c d|c d]
[---+---]
[a b|a b]
[c d|c d]
sage: MQ.parent()
Full MatrixSpace of 4 by 4 dense matrices over Symbolic Ring
sage: MQ.det()
0

more

>mq = matrix(SR, 2, 2, 'a b c d'.split(' '))<, the variables "a, b, c, d" do not appear in workspace, why?

( 2013-11-23 05:39:25 +0100 )edit

There is no reason to inject the symbolic variable a in the python variable a. If i write print('a'), this will not inject the string 'a' into the python variable a.

( 2013-11-23 06:12:40 +0100 )edit

yes, I agree.

( 2013-11-23 06:18:32 +0100 )edit

By the way, if you want to deal with a symbolic variable a but not inject it in the python variable a, you can do SR.var('a') instead of var('a').

( 2013-11-23 08:11:51 +0100 )edit

ah.. thanks!

( 2013-11-24 06:20:15 +0100 )edit
sage: mq = matrix(SR, 2, 2, 'a b c d'.split(' '))
sage: MQ = block_matrix(SR, 2, 2, [mq, mq, mq, mq]); MQ
[a b|a b]
[c d|c d]
[---+---]
[a b|a b]
[c d|c d]
sage: MQ.det()
0


Is it what you want?

more