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.Sat, 02 Apr 2011 14:45:52 +0200block_matrix confusion (matrix constructor rewrite in new versions of Sage)https://ask.sagemath.org/question/8044/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](http://www.sagemath.org/doc/reference/sage/matrix/constructor.html#sage.matrix.constructor.block_matrix), 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.Sat, 02 Apr 2011 11:56:08 +0200https://ask.sagemath.org/question/8044/block_matrix-confusion-matrix-constructor-rewrite-in-new-versions-of-sage/Answer by DSM for <p><strong>Solved - My mistake - I was running an older version of Sage</strong></p>
<p>I'm having trouble making use of the block_matrix function. I can't even recreate simple examples from the <a href="http://www.sagemath.org/doc/reference/sage/matrix/constructor.html#sage.matrix.constructor.block_matrix">block_matrix documentation</a>, for example</p>
<pre><code>sage: A = matrix(QQ, 2, 2, [3,9,6,10])
sage: X=block_matrix([ [A, -A], [~A, 100*A] ])
</code></pre>
<p>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.</p>
<p>(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.)</p>
<p>I did not import numpy, I did not believe it was necessary. But there's no difference when I do.</p>
<p>Thanks in advance to this magnificent community of sage-masters.</p>
<p>Edit: I have an old version of Sage (4.4). I should have run <code>block_matrix?</code> 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.</p>
https://ask.sagemath.org/question/8044/block_matrix-confusion-matrix-constructor-rewrite-in-new-versions-of-sage/?answer=12248#post-id-12248This 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. :^)Sat, 02 Apr 2011 12:02:29 +0200https://ask.sagemath.org/question/8044/block_matrix-confusion-matrix-constructor-rewrite-in-new-versions-of-sage/?answer=12248#post-id-12248Comment by David Ferrone for <p>This works for me in 4.6.2:</p>
<pre><code>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]
</code></pre>
<p>Previously I think you had to write</p>
<pre><code>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]
</code></pre>
<p>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. :^)</p>
https://ask.sagemath.org/question/8044/block_matrix-confusion-matrix-constructor-rewrite-in-new-versions-of-sage/?comment=21927#post-id-21927Oh, silly mistake on my part. Thanks! I've been using 4.4. I'll see about updating.Sat, 02 Apr 2011 14:45:52 +0200https://ask.sagemath.org/question/8044/block_matrix-confusion-matrix-constructor-rewrite-in-new-versions-of-sage/?comment=21927#post-id-21927