I am trying to collect all terms with non-negative powers of x in polynomials like 1x2(ax2+xπ+x+z)2
First expand the polynomial
Expand[1/x^2 (x + x^Ï€ + a x^2 + z)^2, x]
This gives a2x2+2axπ+2ax+2az+2xπ−2z+x2π−2+2xπ−1+z2x2+2zx+1.
Now try to select those terms with positive or zero powers of x. My best guess is
Plus@@Cases[%, (Times[___, Power[x, g_.], ___] /; g >= 0)]
However, this only yields the term a2x2.
And why does this not work for the other terms? How can I collect the other terms with positive or zero powers of x?
Answer
Alternatively, you can use Pick
and Exponent
:
list = List @@ Expand[1/x^2 (x + x^Pi + a x^2 + z)^2, x];
Pick[list, Positive[Exponent[#, x] & /@ list]]
(*{2 a x,a^2 x^2,2 x^(-1+Pi),2 a x^Pi,x^(-2+2 Pi),2 x^(-2+Pi) z}*)
Or a little shorter, since Exponent
has attribute Listable
(thanks to Mr. Wizard for pointing that out):
Pick[list, Positive@Exponent[list, x]]
Comments
Post a Comment