I'm having trouble finding a way (if there is) to analyse an expression, identify a complex pattern in it and then replace it with another thing. I think it will be easier to explain my problem with the code.
I have these expressions for mx and my:
mz = MZ[x, y, t];
ang = ANG[t];
mzX = D[mz, x];
mzY = D[mz, y];
mod = Sqrt[(1 - mz^2)/(mzX^2 + mzY^2)];
mx = mod (Cos[ang] mzX + Sin[ang] mzY);
my = mod (-Sin[ang] mzX + Cos[ang] mzY);
I calculate the derivative of mx with respect to t, which yields a very complicated expression:
deriv = D[mx, t]
I want to identify the parts of it matching the definitions for mx and my. That may involve regrouping terms, distributing products, etc. And then, I want to replace those parts with "mx" and "my" to get an expression simpler to the eye. Note that FullSimplify does not achieve what I need.
Can anyone please help me?