MathGroup Archive 2008

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

Search the Archive

Re: How to substitute a function?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg94107] Re: [mg94082] How to substitute a function?
  • From: Daniel Lichtblau <danl at wolfram.com>
  • Date: Fri, 5 Dec 2008 05:29:40 -0500 (EST)
  • References: <200812041216.HAA27740@smc.vnet.net>

Alexei Boulbitch wrote:
> Dear crew,
> 
> I faced a difficulty when trying to substitute a newly represented 
> function into an expression containing a sum of differential and 
> algebraic terms. The difficulty is namely, that Mathematica 6 
> substitutes the new representation into the algebraic, but not into the 
> differential part. For example:
> 
> (* This is the definition of a simple example of such an expression *)
> 
> expr = \!\(
> \*SubscriptBox[\(\[PartialD]\), \(x\)]\ \(y[x]\)\) + a*y[x]^2;
> 
> (* Here I substitute a new representation of the function  into the \
> above expression *)
> (* What I expect to get is the following expression: -Exp[-x]*f[x] + \
> Exp[-x]*f´[x] + a \[ExponentialE]^(-2 x) f[x]^2  *)
> (* Instead I get something else. Please have a look and check:  *)
> expr /. y[x] -> Exp[-x]*f[x]
> 
> (* This is another approach I could think of with even worse result. *)
> 
> (* Note however, that within this approach a miracle happened: once \
> it *)
> (* worked as expected (i.e. the substitution of both terms has been \
> performed as desired, but only once *)
> 
> FullSimplify[expr, y[x] == Exp[-x]*f[x]]
> 
> 
> Do you have idea of how to instruct Mathematica to make the substitution 
> everywhere?
> 
> Thank you in advance, Alexei

One way is to use a helper function to make rules to handle the 
differential replacements, given the algebraic one. The one below works 
for your example. Modify as needed to handle e.g. PDEs or use of 
Mathematica's pure funtions.

makeSubstRules[v_, fun_, var_] := {v[var] -> fun,
   HoldPattern[Derivative[j_Integer][v][var]] :> D[fun, {var, j}]}

In[44]:= expr /. makeSubstRules[y, Exp[-x]*f[x], x]
Out[44]= (-E^(-x))*f[x] + (a*f[x]^2)/E^(2*x) + Derivative[1][f][x]/E^x

Daniel Lichtblau
Wolfram Research



  • Prev by Date: Re: How to substitute a function?
  • Next by Date: Re: Rearranging expressions in a user-defined form
  • Previous by thread: How to substitute a function?
  • Next by thread: Re: How to substitute a function?