I have expressions like
tc*Cos[2*w*(t0+tc)]
and I want to replace tc
by something else, but only if it occurs inside Cos
, i.e. the outer tc
should remain as is. Is there any way of specifying the context in which Replace
should act? Maybe some clever pattern tricks?
Note that the actual expressions I'm working on are more complicated and consist of more (similar) terms, so just skipping over the first occurrence isn't going to cut it.
Thanks!
ReplaceAll[c_Cos?(Not@*FreeQ[tc]):>ReplaceAll[c, tc->new]]
should do it. It's not a nice pattern to work with. Will be slow. But if thetc
can appear in an arbitrary expression withinCos
then there's not too much else I know to do. $\endgroup$