# 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?
– S L
Jul 31, 2012 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 Jul 31, 2012 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... Jul 31, 2012 at 12:19
• No, @Yves; I molt on a weekly basis. :) Jul 31, 2012 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.

• This definition doesn't work if the second argument is a number, and OP wanted to be able to evaluate the function... Jul 31, 2012 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. Jul 31, 2012 at 17:33