ASKSAGE: Sage Q&A Forum - Individual question feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Mon, 25 Feb 2019 13:20:05 -0600Strange matrix producthttps://ask.sagemath.org/question/45547/strange-matrix-product/When I enter
A = matrix([[1, 2], [-1, 0], [1, 1]])
B = matrix([[0, 4], [1, -1], [1, 2]])
A*B
I get an error message, as expected.
But when I enter
A = matrix(QQ, [[1, 2], [-1, 0], [1, 1]])
B = matrix(QQ, [[0, 4], [1, -1], [1, 2]])
A*B
I get the output
[ 1 0]
[ 1 -2]
[ 1 3]
However, if I try
A = matrix(QQ, [[1, 2], [-1, 0], [1, 1]])
B = matrix(QQ, [[0, 4], [1, -1], [1, 2], [2, 2]])
A*B
I get an error message.
In all of the examples I try, Sage will give some output for a matrix product of two matrices of the same size as long as the field QQ is specified for at least one of the matrices. I’ve searched online and haven’t found anything to help me understand this. This will be problematic for my students who might draw the conclusion that the standard matrix product is defined when it really isn't. Can anyone help me understand this?Mon, 25 Feb 2019 07:50:00 -0600https://ask.sagemath.org/question/45547/strange-matrix-product/Answer by slelievre for <p>When I enter</p>
<pre><code>A = matrix([[1, 2], [-1, 0], [1, 1]])
B = matrix([[0, 4], [1, -1], [1, 2]])
A*B
</code></pre>
<p>I get an error message, as expected.</p>
<p>But when I enter</p>
<pre><code>A = matrix(QQ, [[1, 2], [-1, 0], [1, 1]])
B = matrix(QQ, [[0, 4], [1, -1], [1, 2]])
A*B
</code></pre>
<p>I get the output</p>
<pre><code>[ 1 0]
[ 1 -2]
[ 1 3]
</code></pre>
<p>However, if I try</p>
<pre><code>A = matrix(QQ, [[1, 2], [-1, 0], [1, 1]])
B = matrix(QQ, [[0, 4], [1, -1], [1, 2], [2, 2]])
A*B
</code></pre>
<p>I get an error message.</p>
<p>In all of the examples I try, Sage will give some output for a matrix product of two matrices of the same size as long as the field QQ is specified for at least one of the matrices. I’ve searched online and haven’t found anything to help me understand this. This will be problematic for my students who might draw the conclusion that the standard matrix product is defined when it really isn't. Can anyone help me understand this?</p>
https://ask.sagemath.org/question/45547/strange-matrix-product/?answer=45549#post-id-45549Thanks for catching this! Indeed an oversight.
Fixing this is now tracked at
- [Sage Trac ticket 27352: Add checks for matrix multiplication](https://trac.sagemath.org/ticket/27352)
-----
Update (2019-05-06). The fix was merged in SageMath 8.7.beta7
and is in particular available in SageMath 8.7, released 2019-03-23.Mon, 25 Feb 2019 13:20:05 -0600https://ask.sagemath.org/question/45547/strange-matrix-product/?answer=45549#post-id-45549