Help with grouping terms (maple)

566 Views Asked by At

I want to collect "coefficients" of polynomial over $x$ in some power, e.g.:

$p:=a \cdot x^3 + b \cdot x^2 + c \cdot x + d$

$collect(p, x^2) = (a\cdot x+b)\cdot x^2 + (c\cdot x+d)$

and extract those two "coefficients" to some variables

$p1:=coeff(p,x^2)$

$p2:=coeff(p,x^2,0)$

but $collect()$ is not intended for such actions. How do I do this in Maple the easiest way?

2

There are 2 best solutions below

0
On BEST ANSWER

You can use prem(p,q,x) which computes the remainder of the polynomial division of $p$ and $q$ in the variable $x$:

p:=a*x^3+b*x^2+c*x+d
q:=x^2
r:=prem(p,q,x)
p:=simplify((p-r)/q)

And then by repeating the last two lines, $r$ will successively take on the values of the "coefficients" of $q^0,q^1,...,q^n$ in the original $p$.

0
On
restart:                        

p := a*x^3+b*x^2+c*x+d;

                              3      2
                      p := a x  + b x  + c x + d

pq := collect(algsubs(x^2=q,p),q);

                      pq := (a x + b) q + c x + d

coeff(pq,q);

                                a x + b

coeff(pq,q,0);

                                c x + d

You could also get both coefficients at once, in the usual ways:

coeffs(pq,q,'t');

                           c x + d, a x + b

t;

                                 1, q

PolynomialTools:-CoefficientList(pq,q);

                          [c x + d, a x + b]