Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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.

EDIT:

Can this be done with the help of Coefficient command?

share|improve this question
1  
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
add comment

1 Answer

up vote 2 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
add comment

Your Answer

 
discard

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.