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.Mon, 12 Nov 2018 23:42:52 +0100How can I invert matrix of matriceshttps://ask.sagemath.org/question/44230/how-can-i-invert-matrix-of-matrices/ Consider:
A = matrix(SR, 2, var('a1,b1,c1,d1'))
B = matrix(SR, 2, var('a2,b2,c2,d2'))
C = matrix(SR, 2, var('a3,b3,c3,d3'))
D = matrix(2,2, [A, B, B.T, C])
D; D.is_invertible()
This gives the matrix D as a matrix of (fully expanded) matrices, and confirms that D is invertible.
However:
D.inverse()
results in
Traceback (click to the left of this block for traceback)
...
AttributeError: 'MatrixSpace_with_category' object has no attribute
'is_field'
Seemingly, one cannot build after all a matrix of matrices, but only of basic ring elements.
----------
Even better, I would prefer to construct a matrix of the (non-commutative, invertible) symbolic variables A, B, C, so as to eliminate the clutter of their constituent elements.Fri, 09 Nov 2018 00:19:59 +0100https://ask.sagemath.org/question/44230/how-can-i-invert-matrix-of-matrices/Answer by dan_fulea for <p>Consider:</p>
<pre><code>A = matrix(SR, 2, var('a1,b1,c1,d1'))
B = matrix(SR, 2, var('a2,b2,c2,d2'))
C = matrix(SR, 2, var('a3,b3,c3,d3'))
D = matrix(2,2, [A, B, B.T, C])
D; D.is_invertible()
</code></pre>
<p>This gives the matrix D as a matrix of (fully expanded) matrices, and confirms that D is invertible.
However:</p>
<pre><code>D.inverse()
</code></pre>
<p>results in</p>
<pre><code>Traceback (click to the left of this block for traceback)
...
AttributeError: 'MatrixSpace_with_category' object has no attribute
'is_field'
</code></pre>
<p>Seemingly, one cannot build after all a matrix of matrices, but only of basic ring elements.</p>
<hr>
<p>Even better, I would prefer to construct a matrix of the (non-commutative, invertible) symbolic variables A, B, C, so as to eliminate the clutter of their constituent elements.</p>
https://ask.sagemath.org/question/44230/how-can-i-invert-matrix-of-matrices/?answer=44234#post-id-44234Use `block_matrix` to insure the result is an element of $M_{4\times 4}$ (over the ring `SR`) and not of $M_{2\times 2}$ with entries in a matrix ring, which is a non-commutative ring, and where strictly speaking the inverse is not implemented.
For instance:
sage: D = block_matrix( 2, 2, [A, B, B.T, C] )
sage: D
[a1 b1|a2 b2]
[c1 d1|c2 d2]
[-----+-----]
[a2 c2|a3 b3]
[b2 d2|c3 d3]
sage: D.is_invertible()
True
sage: DI = D.inverse()
So `DI` could be computed and we have:
sage: (DI*D).simplify_full()
[1 0 0 0]
[0 1 0 0]
[0 0 1 0]
[0 0 0 1]
Fri, 09 Nov 2018 23:57:56 +0100https://ask.sagemath.org/question/44230/how-can-i-invert-matrix-of-matrices/?answer=44234#post-id-44234Comment by Richard_L for <p>Use <code>block_matrix</code> to insure the result is an element of $M_{4\times 4}$ (over the ring <code>SR</code>) and not of $M_{2\times 2}$ with entries in a matrix ring, which is a non-commutative ring, and where strictly speaking the inverse is not implemented.</p>
<p>For instance:</p>
<pre><code>sage: D = block_matrix( 2, 2, [A, B, B.T, C] )
sage: D
[a1 b1|a2 b2]
[c1 d1|c2 d2]
[-----+-----]
[a2 c2|a3 b3]
[b2 d2|c3 d3]
sage: D.is_invertible()
True
sage: DI = D.inverse()
</code></pre>
<p>So <code>DI</code> could be computed and we have:</p>
<pre><code>sage: (DI*D).simplify_full()
[1 0 0 0]
[0 1 0 0]
[0 0 1 0]
[0 0 0 1]
</code></pre>
https://ask.sagemath.org/question/44230/how-can-i-invert-matrix-of-matrices/?comment=44266#post-id-44266Thanks. Too bad inverse is not implemented for matrices over the (invertible) matrix ring.Mon, 12 Nov 2018 23:42:52 +0100https://ask.sagemath.org/question/44230/how-can-i-invert-matrix-of-matrices/?comment=44266#post-id-44266