function for regrouping/factoring the following expression



R Fateman <fateman at cs.berkeley.edu> writes:

> On 7/25/2010 1:11 PM, Julien Martin wrote:
>> Hello,
>> I would like to find the Maxima function for isolating the x^3, x^2,
>> x in say, the following expression:
>> A*x^2 + B*x^3 -2*B*x^2 +A*x-5*B*x+3*B
>> So that I have (A-2*B)*x^2 etc... with x^3, x^2 and x appearing only
>> once in the resulting expression.
>
> try rat(...,X);

As Richard Fateman said, but if you want to actually get the
coefficients, use the coeff function afterwards:

(%i1) A*x^2 + B*x^3 - 2*B*x^2 + A*x - 5*B*x + 3*B;
                    3        2                    2
(%o1)              x  B - 2 x  B - 5 x B + 3 B + x  A + x A
(%i2) rat(%, x);
                     3                2
(%o2)/R/          B x  + (- 2 B + A) x  + (- 5 B + A) x + 3 B
(%i3) coeff(%o2, x, 3);
(%o3)/R/                               B
(%i4) coeff(%o2, x, 2);
(%o4)/R/                           - 2 B + A
(%i5) coeff(%o2, x, 1);
(%o5)/R/                           - 5 B + A
(%i6) coeff(%o2, x, 0);
(%o6)/R/                              3 B
(%i7) 

(note that coeff doesn't do anything _that_ clever, so if your power
of x isn't explicit, it won't work:

(%i7) coeff( (x+2)^500, x, 3);
(%o7)                                  0

which is why it's always a good idea to make sure everything's fully
expanded in terms of x first)


Rupert
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 315 bytes
Desc: not available
URL: <http://www.math.utexas.edu/pipermail/maxima/attachments/20100725/e550942f/attachment.pgp>;