0
$\begingroup$

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?

$\endgroup$
  • 1
    $\begingroup$ Why (f^\[Prime]\[Prime])[z] instead of Derivative[2][f][z] ? $\endgroup$ – b.gates.you.know.what Nov 20 '12 at 14:40
  • $\begingroup$ This seems to work Collect[expr // Together // Numerator, Subscript[z^2, _, _], Simplify] $\endgroup$ – chris Nov 20 '12 at 14:46
2
$\begingroup$

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

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

Mathematica graphics

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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