Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Coefficient of Polynomial Function in a loop

Hello so I am using the .coefficient function to extract the coefficient of a monomial given some polynomial. For example, 3x^(2).coefficient(x^(2)) is 3.

R.<x,y,z,w> = QQ[]
List1= [x^(2), y^(2),z^(2)]
List2= [x^(2)+y^(2)+z^(2), 3*x^(2),4*y^(2)]

For example if I do List2[0].coefficient(List1[0]), Sage immediately outputs 1. However, when I try to run it through all of List1, for some reason, the runtime seems to go forever so I feel I am doing something wrong. Even if I restrict to only the first term in List2, the runtime is very long and doesn't stop. Am I doing something wrong? In the code below, it should only run through 3 terms.

    while i<len(List1):