The coefficient command computes the coefficient of X^D in a polynomial A.
f = 3*x^2 + 5*x + 7; coefficient(f,x,2); 3 g = 3*x*y + 4*x^2*y + 1; coefficient(g,y,1); 3*x+4*x^2