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.Thu, 07 Dec 2017 01:46:08 +0100polynomial with matrix coefficientshttps://ask.sagemath.org/question/39981/polynomial-with-matrix-coefficients/Is there a way in sage to work with polynomials or power series over a ring of matrices? For example, I can write something like:
z=var('z')
A=matrix([[z^2+z+1,z],[0,z^2]])
But then lets say I do some transformations and want to recover from the result the matrix coefficient of a particular term. With the matrix above I can write something like
A[0,1].coefficient(z)
or
A[1,0].coefficient(z)
to try to get the individual entries. But what I want is a function that takes A.coefficient(z,2) and returns
[1 0]
[0 1]
Is there a way to do this?Wed, 06 Dec 2017 22:06:14 +0100https://ask.sagemath.org/question/39981/polynomial-with-matrix-coefficients/Answer by tmonteil for <p>Is there a way in sage to work with polynomials or power series over a ring of matrices? For example, I can write something like:</p>
<p>z=var('z')
A=matrix([[z^2+z+1,z],[0,z^2]])</p>
<p>But then lets say I do some transformations and want to recover from the result the matrix coefficient of a particular term. With the matrix above I can write something like</p>
<p>A[0,1].coefficient(z)</p>
<p>or</p>
<p>A[1,0].coefficient(z) </p>
<p>to try to get the individual entries. But what I want is a function that takes A.coefficient(z,2) and returns</p>
<p>[1 0]
[0 1] </p>
<p>Is there a way to do this?</p>
https://ask.sagemath.org/question/39981/polynomial-with-matrix-coefficients/?answer=39985#post-id-39985You if you want the quadratic coefficient of a polynomial symbolic expression P, you can do `P.coefficient(z^2)`, so what you can do is to apply that map to each entry of the matrix:
sage: A.apply_map(lambda e : e.coefficient(z^2))
[1 0]
[0 1]
Thu, 07 Dec 2017 01:46:08 +0100https://ask.sagemath.org/question/39981/polynomial-with-matrix-coefficients/?answer=39985#post-id-39985