# 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.

edit retag close merge delete

Sort by » oldest newest most voted

Use 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]

more

Thanks. Too bad inverse is not implemented for matrices over the (invertible) matrix ring.