# Derivative of multivariable function

I'm trying to use Derivative to differentiate a multivariable function and evaluate it at a value to be determined later. I am able to do it for a function of 1 variable, but not a function of 2 variables.

Here is an example:

Clear[fun1, dfun1, fun2, dfun2]
fun1[a_Integer, x_] := a*x^2
dfun1[a_Integer, x_] = Derivative[0, 1][fun1][a, x]
fun2[x_] := fun1[5, x]
dfun2[x_] = Derivative[fun2][x]
{fun1[a, x], dfun1[a, x], fun2[x], dfun2[x]} /. {a -> 5, x -> 1/2}


The corresponding output is

{5/4, ($\text{fun1}^{(0,1)})$[5,1/2], 5/4, 5}

The problem is the second element, which should be 5.

What am I missing here?

Another method is to wrap the Derivative in an Assuming.

fun1[a_Integer, x_] := a*x^2


Apply the assumption that a belongs to the set of Integers.

Assuming[a ∈ Integers, Derivative[0, 1][fun1][a, x]]

(* 2 a x *)


The _Integer pattern is preventing Mathematica from figuring out the derivative. Use either:

fun1[a_, x_] := a x^2


or:

dfun1 = Derivative[0,1][fun1] = 2 #1 #2&