ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Sun, 24 Nov 2013 08:08:14 +0100Determinant of block matriceshttps://ask.sagemath.org/question/10766/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
Sat, 23 Nov 2013 02:45:41 +0100https://ask.sagemath.org/question/10766/determinant-of-block-matrices/Comment by gundamlh for <p>I need to calculate the determinant of a symbolic 4x4 matrix M, where each cell itself is a matrix itself. </p>
<p>Is that possible?</p>
<p>I did a beginner's check, and it did not seem to work:</p>
<pre><code>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
</code></pre>
https://ask.sagemath.org/question/10766/determinant-of-block-matrices/?comment=16635#post-id-16635Hey, are you from Germany?Sun, 24 Nov 2013 08:08:14 +0100https://ask.sagemath.org/question/10766/determinant-of-block-matrices/?comment=16635#post-id-16635Answer by gundamlh for <p>I need to calculate the determinant of a symbolic 4x4 matrix M, where each cell itself is a matrix itself. </p>
<p>Is that possible?</p>
<p>I did a beginner's check, and it did not seem to work:</p>
<pre><code>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
</code></pre>
https://ask.sagemath.org/question/10766/determinant-of-block-matrices/?answer=15721#post-id-15721 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?Sat, 23 Nov 2013 05:35:14 +0100https://ask.sagemath.org/question/10766/determinant-of-block-matrices/?answer=15721#post-id-15721Answer by tmonteil for <p>I need to calculate the determinant of a symbolic 4x4 matrix M, where each cell itself is a matrix itself. </p>
<p>Is that possible?</p>
<p>I did a beginner's check, and it did not seem to work:</p>
<pre><code>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
</code></pre>
https://ask.sagemath.org/question/10766/determinant-of-block-matrices/?answer=15720#post-id-15720You 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
Sat, 23 Nov 2013 05:17:00 +0100https://ask.sagemath.org/question/10766/determinant-of-block-matrices/?answer=15720#post-id-15720Comment by gundamlh for <p>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:</p>
<pre><code>sage: MQ.parent()
Full MatrixSpace of 2 by 2 dense matrices over Symbolic Ring
</code></pre>
<p>Moreover, there is a kind of contradiction, since you ask the base ring to be <code>SR</code> but your entries are in the set of 2 by 2 martices over <code>SR</code>. If you remove this contradiction, you get:</p>
<pre><code>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]
</code></pre>
<p>To define a block matrix (so that sage understands that it is a 4 by 4 matrix over <code>SR</code>), you should do:</p>
<pre><code>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
</code></pre>
https://ask.sagemath.org/question/10766/determinant-of-block-matrices/?comment=16650#post-id-16650yes, I agree.Sat, 23 Nov 2013 06:18:32 +0100https://ask.sagemath.org/question/10766/determinant-of-block-matrices/?comment=16650#post-id-16650Comment by gundamlh for <p>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:</p>
<pre><code>sage: MQ.parent()
Full MatrixSpace of 2 by 2 dense matrices over Symbolic Ring
</code></pre>
<p>Moreover, there is a kind of contradiction, since you ask the base ring to be <code>SR</code> but your entries are in the set of 2 by 2 martices over <code>SR</code>. If you remove this contradiction, you get:</p>
<pre><code>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]
</code></pre>
<p>To define a block matrix (so that sage understands that it is a 4 by 4 matrix over <code>SR</code>), you should do:</p>
<pre><code>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
</code></pre>
https://ask.sagemath.org/question/10766/determinant-of-block-matrices/?comment=16637#post-id-16637ah.. thanks!Sun, 24 Nov 2013 06:20:15 +0100https://ask.sagemath.org/question/10766/determinant-of-block-matrices/?comment=16637#post-id-16637Comment by tmonteil for <p>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:</p>
<pre><code>sage: MQ.parent()
Full MatrixSpace of 2 by 2 dense matrices over Symbolic Ring
</code></pre>
<p>Moreover, there is a kind of contradiction, since you ask the base ring to be <code>SR</code> but your entries are in the set of 2 by 2 martices over <code>SR</code>. If you remove this contradiction, you get:</p>
<pre><code>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]
</code></pre>
<p>To define a block matrix (so that sage understands that it is a 4 by 4 matrix over <code>SR</code>), you should do:</p>
<pre><code>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
</code></pre>
https://ask.sagemath.org/question/10766/determinant-of-block-matrices/?comment=16649#post-id-16649By 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')`.Sat, 23 Nov 2013 08:11:51 +0100https://ask.sagemath.org/question/10766/determinant-of-block-matrices/?comment=16649#post-id-16649Comment by tmonteil for <p>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:</p>
<pre><code>sage: MQ.parent()
Full MatrixSpace of 2 by 2 dense matrices over Symbolic Ring
</code></pre>
<p>Moreover, there is a kind of contradiction, since you ask the base ring to be <code>SR</code> but your entries are in the set of 2 by 2 martices over <code>SR</code>. If you remove this contradiction, you get:</p>
<pre><code>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]
</code></pre>
<p>To define a block matrix (so that sage understands that it is a 4 by 4 matrix over <code>SR</code>), you should do:</p>
<pre><code>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
</code></pre>
https://ask.sagemath.org/question/10766/determinant-of-block-matrices/?comment=16651#post-id-16651There 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`.Sat, 23 Nov 2013 06:12:40 +0100https://ask.sagemath.org/question/10766/determinant-of-block-matrices/?comment=16651#post-id-16651Comment by gundamlh for <p>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:</p>
<pre><code>sage: MQ.parent()
Full MatrixSpace of 2 by 2 dense matrices over Symbolic Ring
</code></pre>
<p>Moreover, there is a kind of contradiction, since you ask the base ring to be <code>SR</code> but your entries are in the set of 2 by 2 martices over <code>SR</code>. If you remove this contradiction, you get:</p>
<pre><code>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]
</code></pre>
<p>To define a block matrix (so that sage understands that it is a 4 by 4 matrix over <code>SR</code>), you should do:</p>
<pre><code>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
</code></pre>
https://ask.sagemath.org/question/10766/determinant-of-block-matrices/?comment=16653#post-id-16653>mq = matrix(SR, 2, 2, 'a b c d'.split(' '))<, the variables "a, b, c, d" do not appear in workspace, why?Sat, 23 Nov 2013 05:39:25 +0100https://ask.sagemath.org/question/10766/determinant-of-block-matrices/?comment=16653#post-id-16653