Re: substitution of functions in derivatives
- To: mathgroup at smc.vnet.net
- Subject: [mg3413] Re: substitution of functions in derivatives
- From: villegas (Robert Villegas)
- Date: Wed, 6 Mar 1996 01:45:03 -0500
- Organization: Wolfram Research, Inc.
- Sender: owner-wri-mathgroup at wolfram.com
In article <4h8s8f$om1 at dragonfly.wolfram.com> pyl at ccr.jussieu.fr (lagr e) writes: > I have a problem with mathematica and the rules: > suppose that I use a function in an expression like: > > f=a u[x,y] > > next I derivate it: > > df=D[f,x] > now, I'd like to substitute u[x,y] and to give it the good value say Cos[x,y]: > > df/.u[x_,y_]->Cos[x y] > > the result that I want is of course -(a*y*Sin[x*y]) Here are a couple of straightforward ways to do this. Start with the definitions. In[1]:= f = a u[x, y] Out[1]= a u[x, y] In[2]:= df = D[f, x] (1,0) Out[2]= a u [x, y] Method 1: Temporarily define u as a function ============================================= In[3]:= Block[{u}, u[x_, y_] := Cos[x y] ; df] Out[3]= -(a y Sin[x y]) Method 2: Substitute a pure function for u =========================================== In[4]:= df /. u -> Function[{x, y}, Cos[x y]] Out[4]= -(a y Sin[x y]) Method 1 works because if there is a definition for u in effect, and you evaluate an expression containing derivatives of u, the derivatives will automatically differentiate the formula for u. Method 2 works because any derivative operator, such as the Derivative[1, 0] that acts on u in your df, will automatically act on a pure function, differentiating the formula contained in the body. A variant of Method 2 could use a pure function with Slot variables: In[5]:= df /. u -> (Cos[#1 #2]&) Out[5]= -(a y Sin[x y]) Robby Villegas ==== [MESSAGE SEPARATOR] ====