Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

For example,


you can extract its coefficients as follows:


to get

[[2, 0], [7, 3], [2, 4]]

So the last sublist contains the answer, in this case 2 is the coefficient of x^4.

To extract this automatically you can define a function that takes a polynomial as argument:

def get_highest_coeff(P):
    m = P.coefficients()
    ncoeffs = len(m)
    return m[ncoeffs - 1][0]

And use it like this:


to get 2 as the answer. Hope this helps you get going!