2
$\begingroup$

I want to replace the A in the Exponent only but when I use the replace rule it also replaces the Derivative of A.

Exp[A + 2 B] (3 Derivative[1][A] + 4 Derivative[2][A]) /. A -> A + 6 Subscript[f, 3]

which gives me the output

Times[Power[E,Plus[A,Times[2,B],Times[6,Subscript[f,3]]]],Plus[Times[3,Derivative[1][Plus[A,Times[6,Subscript[f,3]]]]],Times[4,Derivative[2][Plus[A,Times[6,Subscript[f,3]]]]]]]

I want the output to show like this

Exp[A + 6 Subscript[f, 3] + 2B] (3 Derivative[1][A] + 4 Derivative[2][A])

Any idea?. Thanks a lot.

$\endgroup$
  • 1
    $\begingroup$ I typically do that like this: Exp[A + 2 B] (3 Derivative[1][A] + 4 Derivative[2][A]) /. Exp[a_] :> Exp[a /. A -> A + 6 Subscript[f, 3]]. Sort of nested replacement. $\endgroup$ – march Dec 20 '18 at 16:13
2
$\begingroup$

You can save the derivatives by prepending another rule to the one you already use. I.e. use:

rules = {e : Derivative[_][A] -> e, A -> A + 6 Subscript[f, 3]}
yourExpression /. rules
$\endgroup$
1
$\begingroup$

Try being more explicit

Exp[A + 2 B] (3 Derivative[1][A] + 4 Derivative[2][A]) /. 
 Exp[A + 2 B] -> Exp[A + 6 Subscript[f, 3] + B]

E^(A + B + 6 Subscript[f, 3]) (3 Derivative[1][A] + 4 A^[Prime][Prime])

Does that help?

On a seperate point I would recommend against using Subscript. You can simply use f[3] and this works well if you need to have a symbolic value in the subscript i.e. f[n]

I hope you enjoy Mathematica.

$\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.