Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2007
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2007

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

Search the Archive

Re: Working with D, definition of a function

  • To: mathgroup at smc.vnet.net
  • Subject: [mg75969] Re: Working with D, definition of a function
  • From: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>
  • Date: Mon, 14 May 2007 03:39:54 -0400 (EDT)
  • Organization: The Open University, Milton Keynes, UK
  • References: <f26nfr$450$1@smc.vnet.net>

Thomas Schmelzer wrote:
> Hi,
> 
> I have defined a map
> 
> ComPath[w_, mu_, bias_] := mu*(\[ImaginaryI]*w + 1)^2 + bias;
> Now, I would like to use the derivative with respect to w as a further 
> function.
> 
> D[ComPath[w, mu, 0], w]
> 
> gives the answer I expect, but
> 
> ComPathPrime[w_, mu_] := D[ComPath[w, mu, 0], w];
> 
> doesn't seem to make sense
> 
> ComPathPrime[2, 1]
> 
> results in
> 
> General::ivar : 2 is  not a valid variable.
> 
> 
> 
> If it seems I have a lack of knowledge about the internals of Mathmatica - 
> that's right.
> 
> Can you briefly explain why this should not work?
> 
> Best,
> 
> Thomas

Note that w is the name of a pattern and the function is defined with a 
SetDelayed. Therefore the pattern named w (and this is also true for mu 
and bias) is going to be replaced on the RHS by the value provided on 
the LHS *before* the actual evaluation (or code execution) takes place. 
That is, when you call ComPathPrime[2, 1], the RHS is rewritten as 
D[ComPath[2, 1, 0], 2], so you attempt to take the derivative w.r.t. to 
2, operation that does not make sense.

The following may achieve what you are looking for.

In[1]:=
ComPath[w_, mu_, bias_] := mu*(I*w + 1)^2 + bias;
ComPathPrime[w_, mu_] = D[ComPath[w, mu, 0], w];
D[ComPath[w, mu, 0], w]
ComPathPrime[2, 1]

Out[3]=
2*I*mu*(1 + I*w)

Out[4]=
-4 + 2*I

Regards,
Jean-Marc


  • Prev by Date: Re: Working with D, definition of a function
  • Next by Date: Re: Mathematica 6: How to add documentation for user packages?
  • Previous by thread: Re: Working with D, definition of a function
  • Next by thread: Re: Working with D, definition of a function