Re: Replace certain variable

*To*: mathgroup at smc.vnet.net*Subject*: [mg74840] Re: [mg74821] Replace certain variable*From*: Andrzej Kozlowski <akoz at mimuw.edu.pl>*Date*: Sat, 7 Apr 2007 04:07:20 -0400 (EDT)*References*: <200704060825.EAA09293@smc.vnet.net>

On 6 Apr 2007, at 17:25, KFUPM wrote: > Dear Group > > If i have a term like : F[w]*Exp[I*w*t] where F[w] is an arbitrary > function, and i want to replace w by x+ s*a only in the exponent not > in F[w], i wonder what is the quickest and easiest way to do it > provided that i have so many similar terms. > > Your help and prompt reply is highly appreciated. > > HMQ > > One way to do it is by first defining a function, call it rep, which will replace w by x+ s*a in any chosen expressions: rep[expr_] := expr /. w :> x + s*a Now, all you need to do is to apply r only to the chosen part of your expression. Of course you have to tell Mathematica somehow which part of your expression you wish to apply rep to. Probably the simplest way to do it is by means of pattern matching: f[w]*Exp[I*w*t] /. p_Power :> rep[p] E^(I*t*(a*s + x))*f[w] If you wanted to apply rep only within f you could do: f[w]*Exp[I*w*t] /. p_f :> rep[p] E^(I*t*w)*f[a*s + x] Of course you can also use other functions such as MapAt: MapAt[rep, f[w]*Exp[I*w*t], {1}] E^(I*t*(a*s + x))*f[w] MapAt[rep, f[w]*Exp[I*w*t], {2}] E^(I*t*w)*f[a*s + x] but this is harder since you need either to know the position of Exp [I*w*t] in f[w]*Exp[I*w*t] or have Mathematica obtain it for you as in MapAt[rep, f[w]*Exp[I*w*t], Position[f[w]*Exp[I*w*t], Exp[I*w*t]]] E^(I*t*(a*s + x))*f[w] which takes more typing than its worth. Andrzej Kozlowski

**References**:**Replace certain variable***From:*"KFUPM" <hussain.alqahtani@gmail.com>