1
$\begingroup$

I would like to select the term Subscript[Cos\[CapitalDelta], Subscript[p, B]] of expression

     Times[Complex[0,32],
        Dot[Cross[OverVector[n],Subscript[OverVector[Δ],1]],
    Subscript[OverVector[Δ],A]],Dot[Subscript[OverVector[Δ],1],Derivative[1]
[Subscript[OverVector[Δ],A]]],
Subscript[CosΔ,
    Subscript[p,B]],
    Subscript[SinΔ,Subscript[p,A]],Derivative[1][Subscript[CosΔ,Subscript[p,B]]],Derivative[1]
    [Subscript[SinΔ,Subscript[p,A]]]]

I can use Take[exp,{-3}] but it is not general. The selection rule should indeed be the terms that start with C. For example, in the above expression, I want terms Subscript[CosΔ, Subscript[p, B]] and Derivative[1][Subscript[CosΔ, Subscript[p, B]]].

For other times I may have expression like

    Times[Complex[0,32],m,Ε2,
Dot[Cross[OverVector[n],Subscript[OverHat[OverVector[p]],A]],
Subscript[OverVector[Δ],A]],Subscript[C,Subscript[p,B]],
Subscript[S,Subscript[p,A]],
Subscript[SinΔ,
Subscript[p,A]],Derivative[1][
Subscript[CosΔ,Subscript[p,B]]]]

For this expression, I really need the term

 Subscript[C, Subscript[p, B]]

Can anyone help me with this?

$\endgroup$
  • $\begingroup$ In your expressions it is not clear, how their terms are connected to one another. Now they are simply written as several different input lines within the same cell. Do they form a list? Or, may be, they should be connected by the sign plus? Or what? Further, what do you mean by such a notation as Subscript[Cos\[CapitalDelta], Subscript[p, B]]? Do you mean, may be, Cos[Subscript[\[CapitalDelta], Subscript[p,B]]]? $\endgroup$ – Alexei Boulbitch Aug 27 '18 at 9:38
  • $\begingroup$ @ Alexei Boulbitch sorry, I have changed the messy code. Now, it is more clear. $\endgroup$ – ZHANG Juenjie Aug 27 '18 at 12:15
  • $\begingroup$ It still seems to contain a syntax error: Subscript[Cos\[CapitalDelta], Subscript[p, B]] does not exist within the Mma syntax, unless you mean that it is such a variable with so a strange name. Further, now your expression represents a single term: a product of several factors. In this case I do not understand the sense of your question. $\endgroup$ – Alexei Boulbitch Aug 27 '18 at 12:55
0
$\begingroup$

In the first case, this may work out:

FullForm /@ Cases[
  exp,
  x : Subscript[a_, b_] /; StringTake[ToString[a], {1, 1}] == "C",
  All
  ]

{Subscript[CosΔ, Subscript[p, B]], Subscript[CosΔ, Subscript[p, B]]}

It does miss the derivative around the second occurrence, though. I don't know whether this iss desired or not.

$\endgroup$
  • $\begingroup$ @ Henrik Schumacher How to take into account the Derivative? $\endgroup$ – ZHANG Juenjie Aug 27 '18 at 12:57
  • 1
    $\begingroup$ Cases[exp, x : (Derivative[1][Subscript[a_, b_]]) | Subscript[a_, b_] /; StringTake[ToString[a], {1, 1}] == "C", All] $\endgroup$ – ZHANG Juenjie Aug 27 '18 at 12:59

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.