Subject: Coefficients in a multivariate polynomial?
From: Stavros Macrakis
Date: Sun, 9 Jun 2013 13:07:56 -0400
There is a package contributed to Maxima called "format" which I think will
handle your problem.
load("format");
mypoly: (1-a^2)*x*y^2+(a^2-b-c)*x*y*z+(2*a-b^2+c)*y*z^2$
fpoly: format(mypoly,%poly(x,y,z)) <<< format as a polynomial in x,y,z
constantterm: subst([x=0,y=0,z=0],mypoly);
nonconstantterms: args(fpoly-constantterm);
You can split that into the coefficients and the polynomial base term like
this:
coeffs: subst([x=1,y=1,z=1],nonconstantterms);
baseterm: nonconstantterms/coeffs;
Unfortunately, though the format package and its documentation are
distributed with the Maxima system, its documentation is not integrated
with Maxima's documentation -- it should be....
To read it, note the output of the "load" command and look in that
directory:
(%i91) load(format);
(%o91)
"C:/PROGRA~2/MAXIMA~1.0-2/share/maxima/5.28.0-2/share/contrib/format/format.mac"
(%i92)
demo("C:/PROGRA~2/MAXIMA~1.0-2/share/maxima/5.28.0-2/share/contrib/format/format.demo");
There is also other documentation in that directory. A PDF version of the
documentation is available
online<https://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=2&ved=0CD4QFjAB&url=http%3A%2F%2Fwww.researchgate.net%2Fpublication%2F228974614_An_expression_formatter_for_Macsyma%2Ffile%2F9fcfd50a3b24858579.pdf&ei=rLW0Ua_2N-yx0AGWhYHADA&usg=AFQjCNGr6VowHHr1j92own2Vfiuzk_zZ8Q&sig2=iXmcR7je4dGuD5Y3gk6z5Q>
.
-s
PS I would appreciate it if you would cite formulas in Maxima syntax, e.g.
2*x*y rather than 2xy. That would make it easier for us to help you.
On Wed, Jun 5, 2013 at 7:55 PM, Alasdair McAndrew <amca01 at gmail.com> wrote:
> Thanks - but how do I obtain a list of all coefficients? That is, with an
> input, say, of
>
> (1-a^2)xy^2+(a^2-b-c)xyz+(2a-b^2+c)yz^2
>
> I want the expressions
>
> 1-a^2, a^2-b-c, 2a-b^2+c
>
> returned. I guess I would need to tell Maxima which are the polynomial
> variables (in this case x, y and z), and somehow pull out the rest. But
> how?
>
> Thanks again,
> Alasdair
>
>
> On Wed, Jun 5, 2013 at 11:56 PM, Richard Fateman <
> fateman at eecs.berkeley.edu> wrote:
>
>> you could try this:
>>
>> r:rat(ex);
>>
>> ratsubst(0,z, ratcoef(r,x^2*y))
>>
>> unfortunately, picking out the coefficient of z^0 is a little tricky, so
>> I used a substitution.
>>
>> It is much faster to do rat() than expand().
>> RJF
>>
>>
>>
>> On 6/5/2013 6:32 AM, Alasdair McAndrew wrote:
>>
>> Suppose I want to find the coefficient of x^2y in the expansion of
>>
>> (x-2*y+3*z-4)^5
>>
>> I can do:
>>
>> (%i1) ex:expand((x-2*y+3*z-4)^5);
>> (%i2) coeff(coeff(coeff(ex,x,2),y,1),z,0);
>>
>> But surely there must be a simpler way than calling three nested coeff's?
>>
>> What I have is an expression which may be considered as a multivariate
>> polynomial, the coefficients being themselves expressions; something like
>>
>> (1-a^2)xy-(a-b)x^2y+(a-b^2+c)xy^2+...
>>
>> I need to be able to extract the coefficients: 1-a^2, a-b, a-b^2+c from
>> this expression. Is there an easy way to do this in Maxima?
>>
>> Thanks,
>> Alasdair
>>
>> --
>> Blog: http://amca01.wordpress.com
>> Web: http://sites.google.com/site/amca01/
>> Facebook: http://www.facebook.com/alasdair.mcandrew
>>
>>
>> _______________________________________________
>> Maxima mailing listMaxima at math.utexas.eduhttp://www.math.utexas.edu/mailman/listinfo/maxima
>>
>>
>>
>> _______________________________________________
>> Maxima mailing list
>> Maxima at math.utexas.edu
>> http://www.math.utexas.edu/mailman/listinfo/maxima
>>
>>
>
>
> --
> Blog: http://amca01.wordpress.com
> Web: http://sites.google.com/site/amca01/
> Facebook: http://www.facebook.com/alasdair.mcandrew
>
> _______________________________________________
> Maxima mailing list
> Maxima at math.utexas.edu
> http://www.math.utexas.edu/mailman/listinfo/maxima
>
>