coefficients of a polynomial in two or more variables
Subject: coefficients of a polynomial in two or more variables
From: Barton Willis
Date: Wed, 2 Dec 2009 19:16:32 -0600
A start:
(%i37) e : ratexpand(4*a*x^2+((c-4*b-a)*y-2*c+a)*x+b*y^2+(d-b)*y-2*d)$
(%i38) list_ratcoeffs(eq, kerns) := block([acc : [], d],
eq : rat(eq),
for kn in kerns do (
d : ratcoef(eq, kn),
eq : eq - d * kn,
acc : cons(d, acc)),
reverse(acc))$
Sort (by hand) the "kernels" from greatest to least total degree:
(%i39) k : [x^2,x*y,y^2,x,y,1]$
(%i40) list_ratcoeffs(e,k);
(%o40) [4*a,c-4*b-a,b,-2*c+a,d-b,-2*d]
Check:
(%i41) e - % . k;
(%o41) 0
Be careful! The order of the kernels matters:
(%i42) list_ratcoeffs(e,reverse(k));
(%o42) [b*y^2+((c-4*b-a)*x+d-b)*y+4*a*x^2+(-2*c+a)*x-2*d,0,0,0,0,0]
Maybe this is a start--let us know when you come up with a good solution.
This is something of general usefulness, I think.
Barton
-----maxima-bounces at math.utexas.edu wrote: -----
>To:?maxima at math.utexas.edu
>From:?Christian?Stengg?<christian.stengg at gmx.at>
>Sent?by:?maxima-bounces at math.utexas.edu
>Date:?12/02/2009?11:55AM
>Subject:?[Maxima]?coefficients?of?a?polynomial?in?two?or?more?variables
>
>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