MathGroup Archive 2008

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

Search the Archive

Re: Defining derivatives

  • To: mathgroup at smc.vnet.net
  • Subject: [mg87981] Re: Defining derivatives
  • From: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>
  • Date: Mon, 21 Apr 2008 06:40:18 -0400 (EDT)
  • Organization: The Open University, Milton Keynes, UK
  • References: <fu9vnl$igu$1@smc.vnet.net> <fueeme$b6g$1@smc.vnet.net> <fuhfi8$isc$1@smc.vnet.net>

dh wrote:

> Hi Jean-Marc,
> 
> is this a typo?: f'[x] ^:= f2[x]
> 
> this would only worj for the variable x.
> 
> Daniel

Hi Daniel,

Wow, that's hurt! You are right, of course. I apologize for the 
confusion that may have resulted.

The correct expression is

     f' ^:= f2;

Nevertheless, this approach is less generic than Carl Woll's solution

     Derivative[1][f1] = f2;

(Note that f' = f2 is also less generic than the above.)

     (* Using up values *)
     Remove["Global`*"]
     f[x_] := f1[x]
     f' ^:= f2
     f'[x]
     D[f[x], x]
     f'[c]
     D[f[c], c]

Out[4]= f2[x]

Out[5]= f1'[x]

Out[6]= f2[c]

Out[7]= f1'[c]

     {* Carl Woll's solution *}
     Remove["Global`*"]
     f[x_] := f1[x]
     Derivative[1][f1] = f2;
     f'[x]
     D[f[x], x]
     f'[c]
     D[f[c], c]

Out[11]= f2[x]

Out[12]= f2[x]

Out[13]= f2[c]

Out[14]= f2[c]

     (* Another possibility, but less generic *)
     Remove["Global`*"]
     f[x_] := f1[x]
     f' = f2;
     f'[x]
     D[f[x], x]
     f'[c]
     D[f[c], c]

Out[18]= f2[x]

Out[19]= f1'[x]

Out[20]= f2[c]

Out[21]= f1'[c]


Best regards,
-- Jean-Marc


> Jean-Marc Gulliet wrote:
> 
>> dh wrote:
> 
>>> Hello All,
> 
> 
>>> does anybody know how to define symbolic derivatives. E.g.:
> 
> 
>>> f[x_]:=f1[x];
> 
> 
>>> f'[x_]:=f2[x];
> 
> 
>>> this does not work because f on the lefthand side is evaluated. To 
> 
> 
>>> prevent this (do not forget to remove f before redefining it):
> 
> 
>>> f[x_]:=f1[x];
> 
> 
>>> HoldPattern[f'[x_]]:=f2[x];
> 
> 
>>> this gives no message, but f'[x] returns f1[x] instead of f2[x].
> 
> 
>>> The same thinhg happens when you change the sequence of definitions:
> 
> 
>>> f'[x_]:=f2[x];
> 
> 
>>> f[x_]:=f1[x];
> 
> 
>> <snip>
> 
> 
>> Daniel,
> 
> 
>> You should use *up values*. You can define them thanks to *UpSet[]* or 
> 
>> *UpSetDelayed[]*. For instance,
> 
> 
>> In[1]:= Remove[f]
> 
>> f[x_] := f1[x]
> 
>> f'[x] ^:= f2[x]
> 
>> f'[x]
> 
> 
>> Out[4]= f2[x]
> 
> 
>> Best regards,
> 
>> -- Jean-Marc
> 
> 
> 
> 



  • Prev by Date: problem during polygon deletion
  • Next by Date: Re: Hamiltonian System with NDSolve
  • Previous by thread: Re: Defining derivatives
  • Next by thread: Re: Defining derivatives