1
$\begingroup$

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[1][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?

$\endgroup$
2
$\begingroup$

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 *)
$\endgroup$
2
$\begingroup$

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&
$\endgroup$

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.