2
$\begingroup$

I have the following function:

eW = fL11(u1L^r + u2L^r) + fM11(u1M^r+ u2M^r) + fH11(u1H^r + u2H^r)

The full form of eW is then:

Plus[Times[Rational[1,3],Plus[Power[u1H,r],Power[u2H,r]]],Times[Rational[1,3],Plus[Power[u1L,r],Power[u2L,r]]],Times[Rational[1,3],Plus[Power[u1M,r],Power[u2M,r]]]]

I want to replace the power r to the specific value 1.5 for all variables u1_

I have tried eW /. r-> 1 , but it does not work.

Can anyone suggest me how to write ReplaceAll correctly?

$\endgroup$
  • $\begingroup$ Do you want to replace only the r's in the exponent of u1* variables, or do you want every r replaced? $\endgroup$ – Robert Jacobson Dec 8 '18 at 4:43
3
$\begingroup$
eW /. Power[a_?(StringMatchQ["u1*"]@*SymbolName), r] :> a^(3/2)

fH11 (u1H^(3/2) + u2H^r) + fL11 (u1L^(3/2) + u2L^r) + fM11 (u1M^(3/2) + u2M^r)

Also

eW /. Power[a_ /; StringMatchQ["u1*"]@SymbolName[a], r] :> a^(3/2)

fH11 (u1H^(3/2) + u2H^r) + fL11 (u1L^(3/2) + u2L^r) + fM11 (u1M^(3/2) + u2M^r)

and

eW /. Power[a : (u1L | u1M | u1H), r] :> a^(3/2)

fH11 (u1H^(3/2) + u2H^r) + fL11 (u1L^(3/2) + u2L^r) + fM11 (u1M^(3/2) + u2M^r)

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