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?
Asked
Active
Viewed 512 times
3 Answers
6
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} *)
b.gates.you.know.what
- 20,103
- 2
- 43
- 84
5
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]];
J. M.'s missing motivation
- 124,525
- 11
- 401
- 574
4
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.
Stephen Luttrell
- 5,044
- 1
- 19
- 18
-
This definition doesn't work if the second argument is a number, and OP wanted to be able to evaluate the function... – J. M.'s missing motivation 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
NestList[x D[#, x] &, Exp[x], 3] /. x-> 1– b.gates.you.know.what Jul 31 '12 at 11:03