I need to collect a polynomial in a variable r. The exponents of r are possbily symbolic.
For example, the expression
Collect[r^(2 a) (1 + r^2) + (1 + a) r^2, r]
r^(2 a) + r^2 (1 + a + r^(2 a))
while what I would like to have is
r^(2 a) + r^2 (1 + a) + r^(2+2 a)
Of course my expression is much more complicated, but this gives the idea of what happens.
What about Expand insted of Collect?
– Fred Simons
Sep 22 at 9:06
@FredSimons I want all the terms that are multiplied by the same power of r to stay together. Expand would not work in this case. I will change the example to make it clearer
Sep 22 at 9:10
Your example with some extra terms:
exp=r^(2 a)+r^2 (1+a+r^(2 a)) + r + a r;
Collect accepts patterns, so you can collect with respect to powers of r:
(* (1+a) r+(1+a) r^2+r^(2 a)+r^(2+2 a) *)