coefficients of a polynomial in two or more variables
Subject: coefficients of a polynomial in two or more variables
From: Sheldon Newhouse
Date: Sat, 05 Dec 2009 23:31:24 -0500
Christian Stengg wrote:
> Dear list,
>
> if I have a polynomial in the variable x, for instance
>
> p:(a*x-b)*(3*x-2)+(c*x+d)*(1-2*x);
>
> I can get the coefficients of the powers of x in the following way:
>
> p_cre:rat(p,x);
> c0:coeff(p_cre,x,0);
> c1:coeff(p_cre,x,1);
> c2:coeff(p_cre,x,2);
>
> I would like to do the same for a polynomial in two (or more) variables
> x and y, for instance for
>
> q:(a*x-b*y)*(4*x-y+1)+(c*x+d)*(y-2);
>
> If I use
>
> q_cre:rat(q,y,x);
>
> I get
>
> 4*a*x^2+((c-4*b-a)*y-2*c+a)*x+b*y^2+(d-b)*y-2*d.
>
> But I would like to get the coefficients of the powers of x and y and of
> the mixed term x*y. I would like it best, if I could write a function
> that does this work automatically for any polynomial in two or more
> variables and returns a list of the coefficients. Can someone give me a
> hint how I could approach this problem?
>
> Thanks for any help,
>
> Christian
>
>
> _______________________________________________
> Maxima mailing list
> Maxima at math.utexas.edu
> http://www.math.utexas.edu/mailman/listinfo/maxima
>
>
For your function
(- y + 4 x + 1) (a x - b y) + (c x + d) (y - 2)
first expand it
(%i38) display2d: false;
Evaluation took 0.0000 seconds (0.0000 elapsed) using 32 bytes.
(%o38) false
(%i39) q;
Evaluation took 0.0000 seconds (0.0000 elapsed) using 0 bytes.
(%o39) (-y+4*x+1)*(a*x-b*y)+(c*x+d)*(y-2)
(%i40) expand(q);
Evaluation took 0.0000 seconds (0.0000 elapsed) using 9.406 KB.
(%o40) b*y^2+c*x*y-4*b*x*y-a*x*y+d*y-b*y+4*a*x^2-2*c*x+a*x-2*d
If you want the coefficient of x*y, this works for me
(%i41) q;
Evaluation took 0.0000 seconds (0.0000 elapsed) using 0 bytes.
(%o41) (-y+4*x+1)*(a*x-b*y)+(c*x+d)*(y-2)
(%i42) coeff(coeff(expand(q),x),y);
Evaluation took 0.0000 seconds (0.0000 elapsed) using 13.211 KB.
(%o42) c-4*b-a
HTH,
-sen