Is it possible to somehow use the expression that Mathematica has collected once the Collect command has been used?

What I mean is, I have an expression like this (this is imaginary example)

(a[x,y]+b[x,y]+c[x,y]^2) z^5+a[x,y]^3 z^4+(b[x,y]+c[x,y]^4) z^3

That I got after I made Collect[expression,z,Simplify].

What I'd like to do is to have command that will, for instance, give me the term that goes along z^5 (the (a[x,y]+b[x,y]+c[x,y]^2))?

I didn't find any examples of it, and Collect in help has no such examples.


Can this be done with the help of Coefficient command?

  • 2
    $\begingroup$ Perhaps Coefficient can be of help? As in Coefficient[expr,z,5] $\endgroup$
    – Peltio
    Nov 15, 2013 at 12:07
  • $\begingroup$ That's it. I knew there had to be some way :) Thanks! $\endgroup$
    – dingo_d
    Nov 15, 2013 at 12:48

1 Answer 1


This is one way:

 ex = (a[x, y] + b[x, y] + c[x, y]^2) z^5 + 
   a[x, y]^3 z^4 + (b[x, y] + c[x, y]^4) z^3;

Coefficient[ex, z^5]

(* a[x, y] + b[x, y] + c[x, y]^2 *)

This is another, if you do not like the first one:

    Plus @@ (List @@ ex[[Position[List @@ ex, z^5][[1, 1]], 2]])

(*  a[x, y] + b[x, y] + c[x, y]^2  *)
  • $\begingroup$ Yup that works, just like Peltio suggested :) $\endgroup$
    – dingo_d
    Nov 15, 2013 at 12:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.