MathGroup Archive 2009

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Replace in operators

  • To: mathgroup at smc.vnet.net
  • Subject: [mg102907] Re: [mg102869] Replace in operators
  • From: Jaebum Jung <jaebum at wolfram.com>
  • Date: Wed, 2 Sep 2009 04:01:02 -0400 (EDT)
  • References: <200909010750.DAA18607@smc.vnet.net>

If f[x] + D[f[x],x] is not evaluated before you apply replacement rule, 
you could hold, replace, and release it:

ReleaseHold[Hold[f[x] + D[f[x], x]] /. f[x] -> g[x]]

But if your expression is evaluated, then you might need to add replace 
rule for derivative..

For example,

rules[f_, g_, n_] :=
 Rule[#1, #2] & @@@
  Table[{D[f[x], {x, i}], D[g[x], {x, i}]}, {i, 0, n}]

In[80]:= f[x]+D[f[x],x]+D[f[x],{x,2}]/.rules[f,g,2]

Out[80]= g[x]+(g^\[Prime])[x]+(g^\[Prime]\[Prime])[x]

- Jaebum

did wrote:
> I can't figure out how to force Mathematica to replace
> f[x] by g[x] in expressions involving operators.
> For example:
>
> f[x] + D[f[x],x] /. f[x] -> g[x]
>
> f is not replaced in the derivative. I found
> somewhere in the manual that the replacement
> does not work on operators, but then it does
> not indicate how to do it.
>
> In my real problem, f[x]->g[x] is a (long)
> list of complicated transformations resulting
> from the resolution of many equations.
> Thus, changing f[x]->g[x] by f->g is not
> an option.
>
> f[x] + D[f[x],x] is actually a complicated
> expression involving many operators.
>
> There are no ways I can do the
> substitution by hand, bit by bit.
>
> Any suggestions ?
> Thanks
>
> PS: it may help to precise the context.
> I'm trying to solve a system of PDEs by
> a small parameter expansion. Solving the
> system at order N, I want to re-inject the
> results into the equations at order N+1.
>
>   



  • Prev by Date: Re: Replace in operators
  • Next by Date: Re: Faster alternative to AppendTo?
  • Previous by thread: Re: Re: Replace in operators
  • Next by thread: Re: Replace in operators