# block_matrix confusion (matrix constructor rewrite in new versions of Sage)

Solved - My mistake - I was running an older version of Sage

I'm having trouble making use of the block_matrix function. I can't even recreate simple examples from the block_matrix documentation, for example

sage: A = matrix(QQ, 2, 2, [3,9,6,10])
sage: X=block_matrix([ [A, -A], [~A, 100*A] ])


I receive the error "Must specify rows or cols for non-square block matrix." When I attempt to set those dimensions I continue to get errors.

(My actual application of this is a bit more complicated, but the dimensions all work out. And I have used block_matrix in another program with symbolic entries. I must have gotten lucky.)

I did not import numpy, I did not believe it was necessary. But there's no difference when I do.

Thanks in advance to this magnificent community of sage-masters.

Edit: I have an old version of Sage (4.4). I should have run block_matrix? to read my specific help file rather than the online documentation. It's working fine, I was simply using the wrong syntax for my version.

edit retag close merge delete

Sort by ยป oldest newest most voted

This works for me in 4.6.2:

sage: A = matrix(QQ, 2, 2, [3,9,6,10])
sage: block_matrix([ [A, -A], [~A, 100*A] ])
[    3     9|   -3    -9]
[    6    10|   -6   -10]
[-----------+-----------]
[-5/12   3/8|  300   900]
[  1/4  -1/8|  600  1000]


Previously I think you had to write

sage: A = matrix(QQ, 2, 2, [3,9,6,10])
sage: block_matrix([A, -A, ~A, 100*A])
[    3     9|   -3    -9]
[    6    10|   -6   -10]
[-----------+-----------]
[-5/12   3/8|  300   900]
[  1/4  -1/8|  600  1000]


or at least you did back in 4.5.1, and it looks like the constructor was rewritten not so long ago. Check your block_matrix's help.. or upgrade, I guess. :^)

more

Oh, silly mistake on my part. Thanks! I've been using 4.4. I'll see about updating.

( 2011-04-02 14:45:52 +0200 )edit