6
$\begingroup$

What's the Mathematica command for

$$f(a,n,k)=\frac{\partial^a}{\partial n^a}\binom{n}{k}$$

I tried

f[a_,n_,k_]:=D[Binomial[n,k], {n,a}] 

but didn't work. To make it work, I had to use

f[a_]:=D[Binomial[n,k], {n,a}]

then I picked a value for $a$ (f[2] for example) to get a function in terms of $n$ and $k$ then I selected values for $n$ and $k$.

Is there one-line command for this? Thank you.

$\endgroup$

3 Answers 3

5
$\begingroup$

The problem you face is, that you must evaluate the derivative relative to n before n is replaced by an argument. One way to achieve this is by using an additional variable: n1. E.g.:

f[a_, n_, k_] := D[Binomial[n1, k],{n1,a}] /. n1 -> n

with this:

f[1, 5, 3]
(* 47/6*)
$\endgroup$
3
  • $\begingroup$ Thanks Dan thats what I'm looking for (+1). $\endgroup$ Commented Apr 11, 2022 at 16:51
  • 1
    $\begingroup$ I think you meant D[Binomial[n1, k], {n1, a}] $\endgroup$
    – Carl Woll
    Commented Apr 11, 2022 at 18:05
  • 1
    $\begingroup$ Yes that's right. Thank you. $\endgroup$ Commented Apr 11, 2022 at 20:28
6
$\begingroup$

Try

Derivative[a, 0][Function[{nn, kk}, Binomial[nn, kk]]][n, k]  

or

Derivative[a, 0][Binomial][n, k] (Thanks @CarlWoll )

$\frac{1}{2} \left( \begin{array}{cc} \{ & \begin{array}{cc} a! \left( \begin{array}{cc} \{ & \begin{array}{cc} 1 & a=2 \\ 2 n-1 & a=1 \\ \end{array} \\ \end{array} \right) & a\geq 1 \\ (n-1) n & \text{True} \\ \end{array} \\ \end{array} \right)$

$\endgroup$
3
  • 3
    $\begingroup$ Simpler is Derivative[a, 0][Binomial][n, k] $\endgroup$
    – Carl Woll
    Commented Apr 11, 2022 at 18:04
  • 1
    $\begingroup$ @AliShadhar See my modified answer $\endgroup$ Commented Apr 12, 2022 at 6:06
  • $\begingroup$ Got it. I also see @bmf's code is simple as well. thank you guys $\endgroup$ Commented Apr 12, 2022 at 9:29
3
$\begingroup$

Another way to do it: use Set rather than SetDelayed

g[a_, n_, k_] = D[Binomial[n, k], {n, a}];

The first derivative

g[1, 5, 3]

476

The second

g[2, 5, 3]

4

$\endgroup$
1
  • $\begingroup$ (+1) This is a typical example, why it is better to use Set, whereever you can, instead of SetDelayed as a standard. I often said. $\endgroup$
    – Akku14
    Commented Jul 19, 2022 at 11:33

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