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.Tue, 20 Mar 2018 00:41:45 +0100Multiplying matrices with different parentshttps://ask.sagemath.org/question/41642/multiplying-matrices-with-different-parents/ I am trying to multiple a symbolic 1x1 matrix with one element in it, by a square matrix over a finite field. for example
[-9*x0^2 - 11*x0*x1 - 5*x1^2 - 11*x0*x2 - 4*x1*x2 + 7*x2^2 + 13*x1*x3 + 8*x2*x3 + 4*x3^2 - 6*x0*x4 - 4*x1*x4 - 15*x2*x4 + 9*x0*x5 - 8*x1*x5 - 5*x2*x5 - 3*x3*x5]
to be multiplied with them matrix
[18 23 14 1 6 21]
[24 3 3 0 2 0]
[17 25 2 16 23 8]
[ 8 21 16 5 1 9]
[14 28 8 17 12 12]
[ 6 24 18 19 3 1]
however when i try this i get the following error:
TypeError: unsupported operand parent(s) for *: 'Full MatrixSpace of 1 by 1 dense matrices over Multivariate Polynomial Ring in x0, x1, x2, x3, x4, x5 over Finite Field of size 31' and 'Full MatrixSpace of 6 by 6 dense matrices over Finite Field of size 31'
Is there a way to do this? Mon, 19 Mar 2018 19:00:57 +0100https://ask.sagemath.org/question/41642/multiplying-matrices-with-different-parents/Comment by dan_fulea for <p>I am trying to multiple a symbolic 1x1 matrix with one element in it, by a square matrix over a finite field. for example </p>
<pre><code>[-9*x0^2 - 11*x0*x1 - 5*x1^2 - 11*x0*x2 - 4*x1*x2 + 7*x2^2 + 13*x1*x3 + 8*x2*x3 + 4*x3^2 - 6*x0*x4 - 4*x1*x4 - 15*x2*x4 + 9*x0*x5 - 8*x1*x5 - 5*x2*x5 - 3*x3*x5]
</code></pre>
<p>to be multiplied with them matrix </p>
<pre><code>[18 23 14 1 6 21]
[24 3 3 0 2 0]
[17 25 2 16 23 8]
[ 8 21 16 5 1 9]
[14 28 8 17 12 12]
[ 6 24 18 19 3 1]
</code></pre>
<p>however when i try this i get the following error:</p>
<p>TypeError: unsupported operand parent(s) for *: 'Full MatrixSpace of 1 by 1 dense matrices over Multivariate Polynomial Ring in x0, x1, x2, x3, x4, x5 over Finite Field of size 31' and 'Full MatrixSpace of 6 by 6 dense matrices over Finite Field of size 31'</p>
<p>Is there a way to do this? </p>
https://ask.sagemath.org/question/41642/multiplying-matrices-with-different-parents/?comment=41651#post-id-41651What should be the result? The $1\times 1$-matrix should be considered as a scalar?
Please also paste some minimal code that reproduces the problem (for instance only one or two variables and a $2\times 2$-matrix), which can be easily copy+pasted. Potential helpers have the same situation in a few seconds in the interpreter...Tue, 20 Mar 2018 00:41:45 +0100https://ask.sagemath.org/question/41642/multiplying-matrices-with-different-parents/?comment=41651#post-id-41651Answer by nbruin for <p>I am trying to multiple a symbolic 1x1 matrix with one element in it, by a square matrix over a finite field. for example </p>
<pre><code>[-9*x0^2 - 11*x0*x1 - 5*x1^2 - 11*x0*x2 - 4*x1*x2 + 7*x2^2 + 13*x1*x3 + 8*x2*x3 + 4*x3^2 - 6*x0*x4 - 4*x1*x4 - 15*x2*x4 + 9*x0*x5 - 8*x1*x5 - 5*x2*x5 - 3*x3*x5]
</code></pre>
<p>to be multiplied with them matrix </p>
<pre><code>[18 23 14 1 6 21]
[24 3 3 0 2 0]
[17 25 2 16 23 8]
[ 8 21 16 5 1 9]
[14 28 8 17 12 12]
[ 6 24 18 19 3 1]
</code></pre>
<p>however when i try this i get the following error:</p>
<p>TypeError: unsupported operand parent(s) for *: 'Full MatrixSpace of 1 by 1 dense matrices over Multivariate Polynomial Ring in x0, x1, x2, x3, x4, x5 over Finite Field of size 31' and 'Full MatrixSpace of 6 by 6 dense matrices over Finite Field of size 31'</p>
<p>Is there a way to do this? </p>
https://ask.sagemath.org/question/41642/multiplying-matrices-with-different-parents/?answer=41643#post-id-41643How do you want to multiply a 1x1 matrix with a 6x6 matrix? Do you want to take the scalar multiple of the 6x6 matrix by the sole entry of the 1x1 matrix? That is something you can do. If your first matrix is A and your second one is B then sage will quite happily compute
A[0,0]*B
Based on the comments below, perhaps you're looking for something like this instead:
sage: R.<x,y>=GF(31)[]
sage: B=matrix(GF(31),2,2,[1,2,3,4])
sage: L=[x^2,x*y,y^2]
sage: [f*B for f in L]
[
[ x^2 2*x^2] [ x*y 2*x*y] [ y^2 2*y^2]
[3*x^2 4*x^2], [3*x*y 4*x*y], [3*y^2 4*y^2]
]Mon, 19 Mar 2018 19:07:11 +0100https://ask.sagemath.org/question/41642/multiplying-matrices-with-different-parents/?answer=41643#post-id-41643Comment by Dalvir for <p>How do you want to multiply a 1x1 matrix with a 6x6 matrix? Do you want to take the scalar multiple of the 6x6 matrix by the sole entry of the 1x1 matrix? That is something you can do. If your first matrix is A and your second one is B then sage will quite happily compute</p>
<pre><code>A[0,0]*B
</code></pre>
<p>Based on the comments below, perhaps you're looking for something like this instead:</p>
<pre><code>sage: R.<x,y>=GF(31)[]
sage: B=matrix(GF(31),2,2,[1,2,3,4])
sage: L=[x^2,x*y,y^2]
sage: [f*B for f in L]
[
[ x^2 2*x^2] [ x*y 2*x*y] [ y^2 2*y^2]
[3*x^2 4*x^2], [3*x*y 4*x*y], [3*y^2 4*y^2]
]
</code></pre>
https://ask.sagemath.org/question/41642/multiplying-matrices-with-different-parents/?comment=41645#post-id-41645Yes that's basically what i want to do, except what i need is not quite as simple as that. I basically have a column vector in which each of it's components is a multivariate equation for example the one i have given above, i need to multiply each of these multivariate equations in the column vector by the 6x6 matrix, so i am trying to treat each multivariate equation as a 1x1 matrix to do so, but i get the error i noted in my question. I don't know if i have made much sense here :/Mon, 19 Mar 2018 19:46:11 +0100https://ask.sagemath.org/question/41642/multiplying-matrices-with-different-parents/?comment=41645#post-id-41645Comment by nbruin for <p>How do you want to multiply a 1x1 matrix with a 6x6 matrix? Do you want to take the scalar multiple of the 6x6 matrix by the sole entry of the 1x1 matrix? That is something you can do. If your first matrix is A and your second one is B then sage will quite happily compute</p>
<pre><code>A[0,0]*B
</code></pre>
<p>Based on the comments below, perhaps you're looking for something like this instead:</p>
<pre><code>sage: R.<x,y>=GF(31)[]
sage: B=matrix(GF(31),2,2,[1,2,3,4])
sage: L=[x^2,x*y,y^2]
sage: [f*B for f in L]
[
[ x^2 2*x^2] [ x*y 2*x*y] [ y^2 2*y^2]
[3*x^2 4*x^2], [3*x*y 4*x*y], [3*y^2 4*y^2]
]
</code></pre>
https://ask.sagemath.org/question/41642/multiplying-matrices-with-different-parents/?comment=41649#post-id-41649??? What do you expect your end result to be? A column vector whose entries are 6x6 matrices? I'm not sure sage will be happy with that. Are you sure it's not just a list of multivariate equations and that you want a list of 6x6 matrices as a result? Putting things in a vector or a matrix imbues the data with an algebraic structure that may not fit your needs. Sometimes a list is better.Mon, 19 Mar 2018 22:47:37 +0100https://ask.sagemath.org/question/41642/multiplying-matrices-with-different-parents/?comment=41649#post-id-41649Comment by Dalvir for <p>How do you want to multiply a 1x1 matrix with a 6x6 matrix? Do you want to take the scalar multiple of the 6x6 matrix by the sole entry of the 1x1 matrix? That is something you can do. If your first matrix is A and your second one is B then sage will quite happily compute</p>
<pre><code>A[0,0]*B
</code></pre>
<p>Based on the comments below, perhaps you're looking for something like this instead:</p>
<pre><code>sage: R.<x,y>=GF(31)[]
sage: B=matrix(GF(31),2,2,[1,2,3,4])
sage: L=[x^2,x*y,y^2]
sage: [f*B for f in L]
[
[ x^2 2*x^2] [ x*y 2*x*y] [ y^2 2*y^2]
[3*x^2 4*x^2], [3*x*y 4*x*y], [3*y^2 4*y^2]
]
</code></pre>
https://ask.sagemath.org/question/41642/multiplying-matrices-with-different-parents/?comment=41650#post-id-41650I think you may be correct with that list interpretation that makes a lot more sense to me, a list of 6x6 matrices as a result is what i require, how would i go about doing this using lists then?? I haven't actually used lists in sage yet :/Mon, 19 Mar 2018 23:11:56 +0100https://ask.sagemath.org/question/41642/multiplying-matrices-with-different-parents/?comment=41650#post-id-41650