# Function that takes derivative of another function (with any number of arguments) and evaluates it

I would like to supply a function as an argument to another function which then differentiates the function and evaluates it at a set of points.

Suppose I want to differentiate this function,

g[x1_, x2_] := x1^2 + x2^2


Doing the following doesn't work,

fDerivative[f_, z__] := Module[{grad = D[f[x], x]}, grad /. {x -> z}]

fDerivative[g, {1, 2}]


returns,

g[{1, 2}]

Any ideas here?

I have also tried,

fDerivative1[f_, z__] := Module[{x, grad}, grad = ND[f[x], x, z]]


But this returns a much longer string of nonsense (to me, am sure that it makes sense to Mathematica!).

Try:

fDerivative[f_, z_] := Module[{x, v},
v = Array[x, Length[z]];
D[f @@ v, {v}] /. Thread[v -> z]
]


g[x1_, x2_] := x1^2 + x2^2
`