[Math] Maple – finding constant coefficient in multivariate polynomial

maple

Is there a command relevant to finding the constant coefficient of any term in a multivariate polynomial in Maple?

For example.

If I have p=2*x*y^2+3*x^2*y. Then I want to specify a monomial term(x*y^2) and be able to extract the coefficient(2). So if I want to find the coefficient of x^2*y^2 it should return 0 and if I want to find the coefficient of x*y it should also return 0 and not 2*y+3*x.

This seems like something "natural" that should be programmed into a "good" software like Maple.

Best Answer

[completely revised: hopefully with better understanding of the question, on account of ensuing comments]

G := proc(P,e,vlist::list(name)) local g, res;
        if e=1 then res:=p
        else
          g:=freeze(e);
          res:=coeff(subs(e=g,P),g);
        end if;
        eval(res,[seq(v=0,v in vlist)]);
     end proc:

p := 7*x^2*y*z^2 + 2*x*y^2 + 3*x^2*y + 17*x*y + 8*x^3*y - 33:

G(p, x, [x,y,z]);
                           0

G(p, y*x^2, [x,y,z]);
                           3

G(p, y^2*x, [x,y,z]);
                           2

G(p, y*x, [x,y,z]);
                           17

G(p, y^2*x^2, [x,y,z]);
                           0

G(p, z^2*x^2*y, [x,y,z]);
                           7

G(p, 1, [x,y,z]);
                          -33
Related Question