4
$\begingroup$

How to generate this type of sequence? $$ f(n, x) = x f'(n-1, x) \hspace{2 mm}, f(0, x) = e^x$$ How do I evaluate it for numerical values for $x = 1$ or any number?

$\endgroup$
6
$\begingroup$

Something like :

NestList[x D[#, x] &, Exp[x], 3]

(* {E^x, E^x x, x (E^x + E^x x), x (E^x + E^x x + x (2 E^x + E^x x))} *)

NestList[x D[#, x] &, Exp[x], 3] /. x-> 1

(* {E, E, 2 E, 5 E} *)
$\endgroup$
  • $\begingroup$ works ... and how do i evaluate it for x=1? $\endgroup$ – Santosh Linkha Jul 31 '12 at 10:39
  • $\begingroup$ You can define a function as @J.M. did or you can take the output and substitute your value for x : NestList[x D[#, x] &, Exp[x], 3] /. x-> 1 $\endgroup$ – b.gates.you.know.what Jul 31 '12 at 11:03
5
$\begingroup$

Leonid's method here can be easily adapted to your example:

experimentX[0, x_] := E^x;
experimentX[n_Integer, x_] := 
  Module[{xl}, 
   Set @@ Hold[experimentX[n, xl_], xl D[experimentX[n - 1, xl], xl]];
   experimentX[n, x]];
$\endgroup$
  • $\begingroup$ Do your gravatars change with Firefox releases? I likes it... $\endgroup$ – Yves Klett Jul 31 '12 at 12:19
  • $\begingroup$ No, @Yves; I molt on a weekly basis. :) $\endgroup$ – J. M. will be back soon Jul 31 '12 at 12:27
4
$\begingroup$

This pair of definitions will do what you want:

Clear[f];
f[n_, x_] /; IntegerQ[n] && n >= 1 := f[n, x] = x D[f[n - 1, x], x] // Simplify;
f[0, x_] = E^x;

It uses "memoisation" to save recomputing earlier results.

$\endgroup$
  • $\begingroup$ This definition doesn't work if the second argument is a number, and OP wanted to be able to evaluate the function... $\endgroup$ – J. M. will be back soon Jul 31 '12 at 16:36
  • $\begingroup$ My apologies. If you insert f[n_, z_?NumericQ] := f[n, x] /. x -> z after the Clear[f] I think it fixes the problem. But this is a bit of a hack because it assumes that you want to use "x" as the dummy variable. $\endgroup$ – Stephen Luttrell Jul 31 '12 at 17:33

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.