Mathematica Asked by Siyi Zhou on May 31, 2021
Now I have a function, say $f(k,z)=e^{-kz}(1+kz)$
I want to find the $n$th $log$ derivative with respect to z.
like $(zpartial_z)^{(n)}f(k,z)$ (or $(partial_{ln z})^{(n)}f(k,z)$
if you like), where the $(n)$ denotes that we take the derivative $n$
times.
I found the answer in this question quite helpful for me to find a general expression for $partial_z^{(n)}f(k,z)$; however, I don’t know how to generalize it to $log$ derivative case using Mathematica. Any suggestions?
Consider
logDiv[f_, n_] := Nest[z D[#, z] &, f, n]
which applies z D[#, z] &
n
times to f
. Then, for instance,
logDiv[k z, 2]
(* k z *)
or
logDiv[Exp[-kz] (1 + k z), 2]
(* E^-kz k z *)
Correct answer by bbgodfrey on May 31, 2021
There is a nice closed form in terms of the Stirling subset numbers for these:
lDerivative[n_Integer?Positive][f_] := Composition[Function, Evaluate] @
(StirlingS2[n, Range[n]].Table[#^[FormalK] Derivative[[FormalK]][f][#],
{[FormalK], 1, n}])
For instance,
lDerivative[8][f][x] == Nest[x D[#, x] &, f[x], 8] // Expand
True
lDerivative[2][Function[z, Exp[-k z] (1 + k z)]][z] // Simplify
E^(-k z) k^2 z^2 (-2 + k z)
Answered by J. M.'s ennui on May 31, 2021
f[k_, z_] = E^(-k*z)*(1 + k*z);
Direct calculation using Nest
dOp1[f_, n_Integer?NonNegative] :=
Nest[z*D[#, z] &, f, n]
Simplify
at each step to reduce number of terms to be differentiated
dOp2[f_, n_Integer?NonNegative] :=
Nest[Simplify[z*D[#, z]] &, f, n]
Transform for straightforward differentiation rather than differential operator
dOp3[f_, n_Integer?NonNegative] :=
D[f /. z -> E^z, {z, n}] /. z -> Log[z]
Equivalent series expansion
dOp4[f_, n_Integer?NonNegative] :=
Sum[StirlingS2[n, i]*z^i*D[f, {z, i}], {i, n}]
Comparing performance of the different approaches
m = 15;
g1 = dOp1[f[k, z], m]; // AbsoluteTiming
(* {0.153352, Null} *)
g2 = dOp2[f[k, z], m]; // AbsoluteTiming
(* {0.11716, Null} *)
g3 = dOp3[f[k, z], m]; // AbsoluteTiming
(* {0.102199, Null} *)
g4 = dOp4[f[k, z], m]; // AbsoluteTiming
(* {0.000697, Null} *)
Verifying that all results are the same
g1 == g2 == g3 == g4 // Simplify
(* True *)
Relative efficiency varies depending on order (n
) and specific function (f
).
Answered by Bob Hanlon on May 31, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP