MathGroup Archive 2009

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

Search the Archive

Re: Error when working with a derivative


Vicent wrote:
> Hello.
> 
> This is my first message to the list.
> 
> I work with Mathematica 7.0.0 on Windows.
> 
> I work with a multiple-variable function, say "MuVaF", and I want to
> define a function which is the partial derivative with respect to one
> of the variables. I tried with this:
> 
>     MuVaF[ex_, ey_] := ex^2 + ey^2 + ex*ey + ex + ey
> 
> Then, if I try to derivate it with respect to "ex":
> 
>     D[MuVaF[ex, ey], ex]
> 
> I get this:
> 
>     1 + 2 ex + ey
> 
> Which sound OK to me. But if I try this:
> 
>     DerivMuVaF[ex_, ey_] := D[MuVaF[ex, ey], ex]
> 
> And then this (trying to evaluate the function for a given point):
> 
>     DerivMuVaF[1, 2]
> 
> I get an error message:
> 
>     General::ivar: 1 is not a valid variable. >>
> 
> I think that's because Mathematica is understanding I am trying to
> perform the derivative on "1"; it is expecting to get a variable and I
> am giving a number instead. So, what's the right way to tell
> Mathematica I want to work with the derivative function of a
> previously defined function??

Use set instead of set-delayed when you define your derivative function. 
That is, use an equal sign without the colon.

derivMuVaF[ex_, ey_] = D[MuVaF[ex, ey], ex]


By the way, it's a good habit to begin your function names with a lower 
case letter, in order to avoid inadvertent conflicts with built-in names 
and symbols.

-- 
Helen Read
University of Vermont


  • Prev by Date: Re: Displaying results in a column
  • Next by Date: Re: Error when working with a derivative
  • Previous by thread: Re: Error when working with a derivative
  • Next by thread: Re: Error when working with a derivative