# How to find the nth derivative?

This question is not the same as my last one. How do you find the $n$-th derivative where $n$ is a variable?

For example, you can find the nth derivative for a specific $n = 3$

D[Log[1 + x], {x, 3}]


but how do you get Mathematica to show the $n$-th derivative for $n$ as a general variable?

For example, from Wolfram Alpha

-
Asked on StackOverflow: stackoverflow.com/q/8278367/618728 –  Mr.Wizard Aug 18 '12 at 18:10

Copying Daniel's method from this StackOverflow question:

For analytic functions you can use SeriesCoefficient.

nthDeriv[f_, x_, n_] := n!*SeriesCoefficient[f[x], {x, x, n}]

f[x_] := 1/x

nthDeriv[f, t, n]

n! Piecewise[{{1/((-t)^n*t), n >= 0}}, 0]

-

Also, sometimes you are just lucky:

t = Table[D[Log[1 + x], {x, n}], {n, 10}]
FindSequenceFunction[t, n]
(*
-> -(-(1/(1 + x)))^n Pochhammer[1, -1 + n]
*)


testing

(FindSequenceFunction[t, n] /. n -> 20) == D[Log[1 + x], {x, 20}]
(* True *)

-

There is another approach that sometimes works better (gives closed-form expressions rather than recurrence relations):

In[1]:= InverseFourierTransform[(-I k)^n FourierTransform[1/(1 + x^2)^Log[2], x, k] , k, x]

Out[1]= (2^(-1 + n - 1/2 Log[1/x^2])
Abs[x]^-Log[2] ((-I)^
n ((1 + n) x Gamma[(1 + n)/2] Gamma[
n/2 + Log[2]] Hypergeometric2F1[(1 + n)/2, n/2 + Log[2], 1/
2, -x^2] (n + Log[4]) -
2 I Gamma[1 + n/2] Gamma[
1/2 (1 + n + Log[4])] ((1 + x^2) Hypergeometric2F1[(2 + n)/
2, 1/2 (1 + n + Log[4]), -(1/2), -x^2] -
Hypergeometric2F1[(2 + n)/2, 1/2 (1 + n + Log[4]), 1/
2, -x^2] (1 + x^2 (3 + 2 n + Log[4])))) +
I^n ((1 + n) x Gamma[(1 + n)/2] Gamma[
n/2 + Log[2]] Hypergeometric2F1[(1 + n)/2, n/2 + Log[2], 1/
2, -x^2] (n + Log[4]) +
2 I Gamma[1 + n/2] Gamma[
1/2 (1 + n + Log[4])] ((1 + x^2) Hypergeometric2F1[(2 + n)/
2, 1/2 (1 + n + Log[4]), -(1/2), -x^2] -
Hypergeometric2F1[(2 + n)/2, 1/2 (1 + n + Log[4]), 1/
2, -x^2] (1 + x^2 (3 + 2 n + Log[4]))))))/((1 + n)
Sqrt[Pi] x Gamma[Log[2]] (n + Log[4]))


It also can be used to find repeated anti-derivatives.

-