MathGroup Archive 1996

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

Search the Archive

Re: substitution of functions in derivatives

  • To: mathgroup at
  • 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

In article <4h8s8f$om1 at> pyl at (lagr e)  

> 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  
> 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]

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


  • Prev by Date: Re: Question : How to force ( Exp[I x]/2+Exp[-I x]/2=cos(x)
  • Next by Date: Re: The 26 problem when reading binary files
  • Previous by thread: Re: substitution of functions in derivatives
  • Next by thread: Re: Find the solutions of two equations