Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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?

share|improve this question

3 Answers 3

up vote 6 down vote accepted

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} *)
share|improve this answer
    
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

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.

share|improve this answer
    
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

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]];
share|improve this answer
    
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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.