MathGroup Archive 2010

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

Search the Archive

Function to differentiate and evaluate any function of several variables


I've just written a handy function to differentiate and evaluate at
the same time any function of several variables.

Here it is.

DD::usage = "DD[f_[params__],diffVars__] where params are the
parameters where we evaluate the differentiated function f and
diffVars is a sequence {variableNumber,differentialOrder} to
differentiate f.";

SetAttributes[DD, HoldFirst];
DD[f_[params__]] := f[params];
DD[f_[params__], diffVars__] :=
      diffList = ConstantArray[0, Length@{params}];
      MapThread[(diffList[[#1]] = #2) &, Transpose[{diffVars}]];
      Derivative[##][f][params] & @@ diffList

f[x_, y_] := x^4 y^2;
DD[f[1, 2], {2, 1}, {1, 3}] (*returns 96*)

Should make it easier to rapidly work with derivatives in Mathematica.


  • Prev by Date: two questions about regression properties
  • Next by Date: Re: Question on defaults in positional arguments
  • Previous by thread: two questions about regression properties
  • Next by thread: How to interpret this integral?