Suppose I have a function p of some arguments:

p[x_,y_]:= (* something *)

Now I with to pass this function as an object to another function, like derivative:

Derivative[0, 2][p[#1, #2] &]

Here I used an expression

p[#1, #2] &

to create a function object.

Can I form it simpler? Neither p not p& worked.

What if I want to pass a function of variable number of arguments to another function?

  • 1
    $\begingroup$ Could you elaborate on what you mean by p didn't work? I tried p[x_, y_] := x^5 y^7; Derivative[0, 2][p] and it gives the correct answer. $\endgroup$ – DumpsterDoofus Nov 22 '14 at 18:13
  • $\begingroup$ If you want to pass the derivative function to another function, just define d02p = Derivative[0, 2][p] and pass d02p to another function. $\endgroup$ – DumpsterDoofus Nov 22 '14 at 18:13

You can define partial derivatives in specified slots without using #1 or #2:

p[x_, y_] := x^5 y^7;
d02p = Derivative[0, 2][p];
d02p[a, b]

which returns

42 a^5 b^5

Likewise, to obtain the pure function fDer for the mixed partial derivative of a function f of vector argument, try this:

f[list_] := (Times @@ list)^8;
ind = RandomInteger[{0, 8}, 10];
fDer = Derivative[ind][f];
fDer[Subscript[a, #] & /@ Range[10]]

which produces $$122787561599926272000 a_1^7 a_3^6 a_4 a_5^8 a_6^6 a_7^6 a_8^8 a_9^7 a_{10}^3.$$


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.