I have a function f(t)=2/(2-t)
. It is not so hard to get the rth derivative at t=0 (i.e. 2^(-r)*r!
) without using Mathematica. In the case of Mathematica calculation, I can get the r-th derivative when r=4 like this: D[2/(2-t), {t, 4}]
. But how can I get the rth derivative at t=0 in Mathematica when r is ANY integer? I tried to use this expression, but it didn't work as expected:
Simplify[D[2/(2 - t), {t, r}], Assumptions -> Element[r, Integers]] /. {t->0}
Is it possible to do the above math symbolically in Mathematica just as we humans do?
f = FindSequenceFunction[Table[D[2/(2 - t), {t, n}], {n, 1, 5}], r]
(*
-> -((2 (2 - t)^-r Pochhammer[1, r])/(-2 + t))
*)
g[r_, t_] := f
FullSimplify@FindSequenceFunction[Table[g[r, t], {r, 1, 5}] /. t -> 0]
(*
-> 2^-#1 Pochhammer[1, #1] &
*)
Edit
Or just
FindSequenceFunction[Table[D[2/(2 - t), {t, n}], {n, 1, 5}], r] /. t -> 0
(*
-> 2^-r Pochhammer[1, r]
*)
*Edit *
Note: While FindSequenceFunction[]
works in this simple situation, don't bet on it in more general cases.
Edit
To get the result expressed in terms of the factorial function, just do:
FunctionExpand@FindSequenceFunction[Table[D[2/(2-t),{t, n}],{n,1,5}], r] /.t->0
(*
-> 2^-r Gamma[1 + r]
*)
For analytic functions you can use SeriesCoefficient.
nthDeriv[f_, x_, n_] := n!*SeriesCoefficient[f[x], {x, x, n}]
Your example:
f[t_] := 2/(t - 2)
nthDeriv[f, t, n]
(*
-> Out[39]= n!*Piecewise[{{-2*(2 - t)^(-1 - n), n >= 0}}, 0]
*)
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.
The other answers make me wonder if I'm not understanding underlying question, but I think you should look at Derivative
instead of D
for this kind of thing.
In[1]:= Remove[f, fD]
f = 2/(2 - #) &;
fD[r_Integer, EvaluatedAt_] := Derivative[r][f][#] &[EvaluatedAt]
Now we have a function that can easily be evaluated for any r and value.
In[4]:= fD[#, 0] & /@ {1, 2, 3, 4, 5, 6}
Out[4]= {1/2, 1/2, 3/4, 3/2, 15/4, 45/4}
来源:https://stackoverflow.com/questions/8278367/how-to-find-a-functions-rth-derivative-when-r-is-symbolic-in-mathematica