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, 11 Feb 2012 16:45:53 +0100Linear transformation from polynomialshttps://ask.sagemath.org/question/8706/linear-transformation-from-polynomials/Suppose I have an unspecified list of degree 1 homogeneous polynomials in several variables, say [X1,X2,X3+3*X4,X0]. This list will define a linear transformation
[X0,X1,X2,X3,X4]|---->[X1,X2,X3+3*X4,X0].
A priori I don't know how many variables or polynomials I will have, since they are found depending on some previous parameters. (The way I have done this, the variables are the generators of a polynomial ring V = PolynomialRing(QQ, dim,'X').)
My question is: How can I transform this list of polynomials into a matrix/linear transformation?
I've tried collecting the coefficients, but the .coefficients() does not work really well for multivariable polynomials since it does not "see the zero terms" (at least I don't know how to do that).Fri, 10 Feb 2012 21:43:44 +0100https://ask.sagemath.org/question/8706/linear-transformation-from-polynomials/Comment by RPC for <p>Suppose I have an unspecified list of degree 1 homogeneous polynomials in several variables, say [X1,X2,X3+3<em>X4,X0]. This list will define a linear transformation
[X0,X1,X2,X3,X4]|---->[X1,X2,X3+3</em>X4,X0].</p>
<p>A priori I don't know how many variables or polynomials I will have, since they are found depending on some previous parameters. (The way I have done this, the variables are the generators of a polynomial ring V = PolynomialRing(QQ, dim,'X').)</p>
<p>My question is: How can I transform this list of polynomials into a matrix/linear transformation?</p>
<p>I've tried collecting the coefficients, but the .coefficients() does not work really well for multivariable polynomials since it does not "see the zero terms" (at least I don't know how to do that).</p>
https://ask.sagemath.org/question/8706/linear-transformation-from-polynomials/?comment=20311#post-id-20311Sorry, I guess I was not too precise. I've edited and hopefully it will make sense now.Sat, 11 Feb 2012 02:17:30 +0100https://ask.sagemath.org/question/8706/linear-transformation-from-polynomials/?comment=20311#post-id-20311Comment by John Palmieri for <p>Suppose I have an unspecified list of degree 1 homogeneous polynomials in several variables, say [X1,X2,X3+3<em>X4,X0]. This list will define a linear transformation
[X0,X1,X2,X3,X4]|---->[X1,X2,X3+3</em>X4,X0].</p>
<p>A priori I don't know how many variables or polynomials I will have, since they are found depending on some previous parameters. (The way I have done this, the variables are the generators of a polynomial ring V = PolynomialRing(QQ, dim,'X').)</p>
<p>My question is: How can I transform this list of polynomials into a matrix/linear transformation?</p>
<p>I've tried collecting the coefficients, but the .coefficients() does not work really well for multivariable polynomials since it does not "see the zero terms" (at least I don't know how to do that).</p>
https://ask.sagemath.org/question/8706/linear-transformation-from-polynomials/?comment=20312#post-id-20312Your question is not clear to me mathematically. What do you mean by transforming a list of polynomials into a matrix or linear transformation?Fri, 10 Feb 2012 23:06:12 +0100https://ask.sagemath.org/question/8706/linear-transformation-from-polynomials/?comment=20312#post-id-20312Answer by parzan for <p>Suppose I have an unspecified list of degree 1 homogeneous polynomials in several variables, say [X1,X2,X3+3<em>X4,X0]. This list will define a linear transformation
[X0,X1,X2,X3,X4]|---->[X1,X2,X3+3</em>X4,X0].</p>
<p>A priori I don't know how many variables or polynomials I will have, since they are found depending on some previous parameters. (The way I have done this, the variables are the generators of a polynomial ring V = PolynomialRing(QQ, dim,'X').)</p>
<p>My question is: How can I transform this list of polynomials into a matrix/linear transformation?</p>
<p>I've tried collecting the coefficients, but the .coefficients() does not work really well for multivariable polynomials since it does not "see the zero terms" (at least I don't know how to do that).</p>
https://ask.sagemath.org/question/8706/linear-transformation-from-polynomials/?answer=13264#post-id-13264How is this?
sage: dim=4
sage: F = PolynomialRing(QQ, dim,'X')
sage: I = F.ideal([x*y for x,y in tuples(F.gens(),2)])
sage: pol = [I.reduce(F.random_element()) for i in range(dim)]
sage: pol
[-3*X2, -39/2*X1 - 1/18*X2, -1/10*X0 - 3*X1 - X2 - 1/5*X3, X2 + 6*X3]
sage: matrix(dim,lambda i,j:pol[i].coefficient(F.gen(j)))
[ 0 0 -3 0]
[ 0 -39/2 -1/18 0]
[-1/10 -3 -1 -1/5]
[ 0 0 1 6]
Sat, 11 Feb 2012 06:10:13 +0100https://ask.sagemath.org/question/8706/linear-transformation-from-polynomials/?answer=13264#post-id-13264Comment by RPC for <p>How is this?</p>
<pre><code>sage: dim=4
sage: F = PolynomialRing(QQ, dim,'X')
sage: I = F.ideal([x*y for x,y in tuples(F.gens(),2)])
sage: pol = [I.reduce(F.random_element()) for i in range(dim)]
sage: pol
[-3*X2, -39/2*X1 - 1/18*X2, -1/10*X0 - 3*X1 - X2 - 1/5*X3, X2 + 6*X3]
sage: matrix(dim,lambda i,j:pol[i].coefficient(F.gen(j)))
[ 0 0 -3 0]
[ 0 -39/2 -1/18 0]
[-1/10 -3 -1 -1/5]
[ 0 0 1 6]
</code></pre>
https://ask.sagemath.org/question/8706/linear-transformation-from-polynomials/?comment=20310#post-id-20310Thanks. That'll do it.Sat, 11 Feb 2012 16:45:53 +0100https://ask.sagemath.org/question/8706/linear-transformation-from-polynomials/?comment=20310#post-id-20310