Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
Perhaps Coefficient can be of help? As in Coefficient[expr,z,5] – Peltio Nov 15 '13 at 12:07
That's it. I knew there had to be some way :) Thanks! – dingo_d Nov 15 '13 at 12:48
up vote 3 down vote accepted

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  *)
share|improve this answer
Yup that works, just like Peltio suggested :) – dingo_d Nov 15 '13 at 12:49

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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