# How to generate a recurrent sequence

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?

-

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} *)

-
works ... and how do i evaluate it for x=1? – Santosh Linkha Jul 31 '12 at 10:39
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 – b.gatessucks Jul 31 '12 at 11:03

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]];

-
Do your gravatars change with Firefox releases? I likes it... – Yves Klett Jul 31 '12 at 12:19
No, @Yves; I molt on a weekly basis. :) – J. M. Jul 31 '12 at 12:27

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.

-
Now, try f[5, 1]. – J. M. Jul 31 '12 at 11:31
Since my hint was apparently too subtle for some people: this definition doesn't work if the second argument is a number, and OP wanted to be able to evaluate the function... – J. M. Jul 31 '12 at 16:36
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. – Stephen Luttrell Jul 31 '12 at 17:33