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.

Suppose that I have an expression:

expr=(2 λ f[
 z]^3 (λ (Subscript[λ, 0, 2] + 
     Subscript[λ, 2, 0]) - Subscript[λ^2, 0, 1] - 
  Subscript[λ^2, 1, 0]) - λ^2 (Subscript[z^2, 0, 
  1] + Subscript[z^2, 1, 0])^2 Derivative[1][f][z]^2 + f[z]^2 (4 λ^2 (-Subscript[z, 0, 2] Subscript[z, 2, 0] + 
     Subscript[z^2, 1, 1]) + 
  2 λ (Subscript[z, 0, 
      1] ((-Subscript[z, 0, 2] + Subscript[z, 2, 
           0]) Subscript[λ, 0, 1] - 
        2 Subscript[z, 1, 1] Subscript[λ, 1, 0]) + 
     Subscript[z^2, 0, 
      1] (Subscript[λ, 0, 2] + Subscript[λ, 2, 
        0]) + Subscript[z, 1, 
      0] (-2 Subscript[z, 1, 1] Subscript[λ, 0, 
         1] + (Subscript[z, 0, 2] - Subscript[z, 2, 
           0]) Subscript[λ, 1, 0] + 
        Subscript[z, 1, 
         0] (Subscript[λ, 0, 2] + Subscript[λ, 2, 
           0]))) - (Subscript[z^2, 0, 1] + Subscript[z^2, 1, 
     0]) (Subscript[λ^2, 0, 1] + Subscript[λ^2, 1,
      0]) + 2 λ^3 ((Subscript[z, 0, 2] + Subscript[z, 2, 
        0]) Derivative[1][f][
       z] + (Subscript[z^2, 0, 1] + Subscript[z^2, 1, 0]) (
       f^\[Prime]\[Prime])[z])) + 2 λ f[
 z] ((Subscript[z^2, 0, 1] + Subscript[z^2, 1, 
     0]) (Subscript[z, 0, 1] Subscript[λ, 0, 1] + 
     Subscript[z, 1, 0] Subscript[λ, 1, 0]) Derivative[1][
    f][z] - λ^2 (Subscript[z^2, 0, 1] + Subscript[z^2, 1, 
     0]) Derivative[1][f][
    z]^2 + λ (2 (-2 Subscript[z, 0, 1] Subscript[z, 1, 0]
          Subscript[z, 1, 1] + 
        Subscript[z, 2, 0] Subscript[z^2, 0, 1] + 
        Subscript[z, 0, 2] Subscript[z^2, 1, 0]) Derivative[1][f][
       z] + (Subscript[z^2, 0, 1] + Subscript[z^2, 1, 0])^2 (
       f^\[Prime]\[Prime])[z])))/(4 λ f[
z] (λ f[z] + Subscript[z^2, 0, 1] + Subscript[z^2, 1, 0]))

and I want to collect the terms of the type

Subscript[z, 0, 1]

and

Subscript[z^2, 0, 1]

here 0, and 1 can be change.

I can do for the first one as

Collect[ expr// ExpandAll, Subscript[z, _, _], Simplify]

but while I try to use

Collect[ expr// ExpandAll, Subscript[z^2, _, _], Simplify]

to collect the second one, it doesn't work, Why?

What's more, can I write a pattern that will collect both of them at the same time?

share|improve this question
    
Why (f^\[Prime]\[Prime])[z] instead of Derivative[2][f][z] ? –  b.gatessucks Nov 20 '12 at 14:40
    
This seems to work Collect[expr // Together // Numerator, Subscript[z^2, _, _], Simplify] –  chris Nov 20 '12 at 14:46

1 Answer 1

As Chris mentioned in the comments above, the following seems to work:

Collect[expr // Together // Numerator, Subscript[z^2, _, _], Simplify]

Mathematica graphics

share|improve this answer

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.