[Date Index]
[Thread Index]
[Author Index]
Re: Error when working with a derivative
*To*: mathgroup at smc.vnet.net
*Subject*: [mg104957] Re: [mg104947] Error when working with a derivative
*From*: Murray Eisenberg <murray at math.umass.edu>
*Date*: Sun, 15 Nov 2009 05:54:30 -0500 (EST)
*Organization*: Mathematics & Statistics, Univ. of Mass./Amherst
*References*: <200911140657.BAA18027@smc.vnet.net>
*Reply-to*: murray at math.umass.edu
In some form or another, you need to use a replacement rule for the
variables after you find the derivative. Here's one way (where I've
simplified the function and variable names):
f[x_, y_] := x^2 + y^2 + x y + x + y
Df1[x_, y_][a_, b_] := D[f[x, y], x] /. Thread[{x, y} :> {a, b}]
Df1[x, y][x, y]
1 + 2 x + y
Df1[x, y][1, 2]
5
Of course you can do the same thing with the second variable (but you
function here is symmetric in its variables!).
Another, nicer, way uses the function Derivative and pure functions:
Clear[Df1]
f[x_, y_] := x^2 + y^2 + x y + x + y
Df1 = Derivative[1, 0][f]
1 + 2 #1 + #2 &
Df1[x, y]
1 + 2 x + y
Df1[a, b]
1 + 2 a + b
Df1[1, 2]
5
This second way is closer to what you can do with the ' (prime)
abbreviation for derivative of a function of a single variable:
g[x_] := x^2 + x
g'[x]
1 + 2 x
g'[2]
5
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??
>
> I guess the answer should be easy, but I haven't been able to find it
> out by my own. :-(
>
> Thank you in advance for your answers!
>
>
> --
> Vicent Giner-Bosch
>
--
Murray Eisenberg murray at math.umass.edu
Mathematics & Statistics Dept.
Lederle Graduate Research Tower phone 413 549-1020 (H)
University of Massachusetts 413 545-2859 (W)
710 North Pleasant Street fax 413 545-1801
Amherst, MA 01003-9305
Prev by Date:
**Re: Fyi, Listing of Mathematica 7 functions (1869 functions)**
Next by Date:
**Re: incorrect display for Export[Image[]]**
Previous by thread:
**Re: Error when working with a derivative**
Next by thread:
**Re: Error when working with a derivative**
| |