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.Wed, 19 Jan 2022 12:32:37 +0100Coefficients of polynomial of fixed degreehttps://ask.sagemath.org/question/60720/coefficients-of-polynomial-of-fixed-degree/How can we extract the coefficient of any polynomial as a fixed degree polynomial? For example, if we have $a=2+3*x$, then a.polynomial().coefficient() will extract (2,3), but I need the polynomial of degree 3, and the output will be (2,3,0,0).Wed, 19 Jan 2022 12:04:24 +0100https://ask.sagemath.org/question/60720/coefficients-of-polynomial-of-fixed-degree/Answer by slelievre for <p>How can we extract the coefficient of any polynomial as a fixed degree polynomial? For example, if we have $a=2+3*x$, then a.polynomial().coefficient() will extract (2,3), but I need the polynomial of degree 3, and the output will be (2,3,0,0).</p>
https://ask.sagemath.org/question/60720/coefficients-of-polynomial-of-fixed-degree/?answer=60721#post-id-60721If `a` lives in a polynomial ring rather than in the symbolic ring,
then `a[k]` extracts the coefficient of `x^k` of `a`, regardless
of the degree of `a`.
Example:
sage: x = polygen(ZZ)
sage: a = 2 + 3*x
sage: [a[k] for k in range(4)]
[2, 3, 0, 0]Wed, 19 Jan 2022 12:32:37 +0100https://ask.sagemath.org/question/60720/coefficients-of-polynomial-of-fixed-degree/?answer=60721#post-id-60721