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.

I have a question where I have to compute a Table containing $f^{(n)}(0)$ for n = 1, ..., 5, where $f^{(n)}$ denotes the $n$th derivative of $f$.

For the function $f(x)=x\mathrm{e}^{-x}$, I have:

f[x_]:=xe^-x
Table[D[f[x],{x,n}],{n,1,5}]//TableForm

How can I solve for the value of each derivative at 0?

share|improve this question

3 Answers 3

Since Vitaliy already answered the question, I'll just add another answer to confuse you. To get the general form of the $n$-th derivative, you could use the properties of the Taylor series as follows:

Clear[n];
c[n_] = FullSimplify[SeriesCoefficient[n! x Exp[-x], {x, 0, n}], 
  n >= 0]

$\begin{cases} -(-1)^n n & n\geq 1 \\ 0 & \text{True} \end{cases}$

This is the $n$-th coefficient in the series expansion of your function around $x = 0$ (with the factorial $n!$ canceled). It is the thing you're supposed to tabulate. To verify this, here is the table explicitly:

Array[c, {5}] // TableForm

$\begin{array}{c} 1 \\ -2 \\ 3 \\ -4 \\ 5 \\\end{array}$

The nice thing about c[n] is of course that you no longer need to make such tables if you have a closed form for the derivatives. If you do want to make tables, though, then c[n] allows you to do this at very high speed because the definition c[n_] = ... using Set (the = sign) caused the right-hand side to be evaluated once and for all, so it doesn't have to be repeated every time you change n.

share|improve this answer
    
Nice touch ;) +1 –  Vitaliy Kaurov Dec 12 '12 at 18:09

You have 2 typos. No space in xe and use capital E not e - or better Exp[x]

You have nicely behaving functions, so this would work:

f[x_] := x Exp[-x]
Table[D[f[x], {x, n}] /. x -> 0, {n, 1, 5}]

{1, -2, 3, -4, 5}

But this is dangerous and it is better to use this:

f[x_] := x Exp[-x]
Table[Limit[D[f[x], {x, n}], x -> 0], {n, 1, 5}]

{1, -2, 3, -4, 5}

To illustrate, imagine you have other function:

f[x_] := SinIntegral[x]
Table[D[f[x], {x, n}], {n, 1, 5}] // FullSimplify // Column

enter image description here

Using /.x- > 0 will now give error due to x in denominator, while Limit is fine:

f[x_] := SinIntegral[x]
Table[Limit[D[f[x], {x, n}], x -> 0], {n, 1, 5}]

{1, 0, -(1/3), 0, 1/5}

share|improve this answer
    
Okay thank you, makes sense adding the limit. –  ppkjref Dec 12 '12 at 5:52
    
(+1) I hope we're not giving away anything that was in some homework problem... –  Jens Dec 12 '12 at 6:29
    
Finding a derivative at 0 by taking the limit as x -> 0 in the "general" formulate for the derivative can be dangerous: a function may be differentiable at a point yet that derivative need not be continuous there. –  murray Dec 12 '12 at 16:46
1  
@murray Evaluation via substitution will go wrong in presence of a removable singularity. Evaluation via limit might go wrong in presence of a discontinuity in the derivative. The latter will, most often, be the less serious mistake. The best to be said for the blind substitution approach is one can try to trap for Indeterminate and switch to a limit. of course if you have (explicit zero)/(hiddfen zero) then the trap fails (Limit can also miss such things but is less likely to do so). –  Daniel Lichtblau Dec 12 '12 at 19:32
3  
NestList[D[#, x] &, f[x], n] will avoid internally recomputing lower derivatives. –  Daniel Lichtblau Dec 12 '12 at 19:32

There is another approach that sometimes works better (gives closed-form expressions rather than recurrence relations):

In[1]:= InverseFourierTransform[(-I k)^n FourierTransform[1/(1 + x^2)^Log[2], x, k] , k, x]
Out[1]= (2^(-1 + n - 1/2 Log[1/x^2])
      Abs[x]^-Log[2] ((-I)^
      n ((1 + n) x Gamma[(1 + n)/2] Gamma[
      n/2 + Log[2]] Hypergeometric2F1[(1 + n)/2, n/2 + Log[2], 1/
      2, -x^2] (n + Log[4]) - 
    2 I Gamma[1 + n/2] Gamma[
      1/2 (1 + n + Log[4])] ((1 + x^2) Hypergeometric2F1[(2 + n)/
         2, 1/2 (1 + n + Log[4]), -(1/2), -x^2] - 
       Hypergeometric2F1[(2 + n)/2, 1/2 (1 + n + Log[4]), 1/
         2, -x^2] (1 + x^2 (3 + 2 n + Log[4])))) + 
 I^n ((1 + n) x Gamma[(1 + n)/2] Gamma[
      n/2 + Log[2]] Hypergeometric2F1[(1 + n)/2, n/2 + Log[2], 1/
      2, -x^2] (n + Log[4]) + 
    2 I Gamma[1 + n/2] Gamma[
      1/2 (1 + n + Log[4])] ((1 + x^2) Hypergeometric2F1[(2 + n)/
         2, 1/2 (1 + n + Log[4]), -(1/2), -x^2] - 
       Hypergeometric2F1[(2 + n)/2, 1/2 (1 + n + Log[4]), 1/
         2, -x^2] (1 + x^2 (3 + 2 n + Log[4]))))))/((1 + n) 
       Sqrt[Pi] x Gamma[Log[2]] (n + Log[4]))

It also can be used to find repeated anti-derivatives.

share|improve this answer
    
This does work, but only if the function decays fast enough to infinity. I don't think it will work for any kind of polynomials. E.g., try x^2: you get indeterminate errors (with n=1). –  Jens May 9 '13 at 6:04
2  
You can use x^2 UnitBox[a x] to workaround this. This approach only sometimes works better. In many cases it is not able to find the transform. –  Vladimir Reshetnikov May 9 '13 at 16:55
    
BTW, there is another cool use for this method: to prove that the Dirac delta function is the limit of the sinc function, one can do this: InverseFourierTransform[ Limit[ FourierTransform[Sin[\[Omega] t]/(\[Pi] \[Omega]),\[Omega],\[Tau]], t->\[Infinity]], \[Tau],\[Omega]] (I actually don't know any better way of getting that result in Mathematica because of the conservative way DiracDelta is defined). –  Jens May 9 '13 at 17:41

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.