Integrating $x^2e^{-x}$ using Feynman's trick? [duplicate]

In the second episode of season $8$ of "The Big Bang Theory," which aired yesterday night, it is stated that one can integrate $x^2e^{-x}$ by using Feynman's trick of differentiating under the integral. Is this actually true, and if so, how to do it? And is it "better," in any sense, than the usual way of doing it by integration by parts?


Solution 1:

If we just compute without thinking about problems such as interchanging integration and differentiation, the derivation is very simple. $$ \int_0^{\infty} x^2e^{-x}dx=\left.\left(\frac{d}{d\alpha}\right)^2\right|_{\alpha=1}\int_0^{\infty} e^{-\alpha x}dx=\left.\left(\frac{d}{d\alpha}\right)^2\right|_{\alpha=1} \frac{1}{\alpha}=\left.\frac{2}{\alpha^3}\right|_{\alpha=1}=2. $$

If you want limits other than the positive real axis, the same trick allows you to arrive at $$ \int_a^{b} x^2e^{-x}dx=\left.\left(\frac{d}{d\alpha}\right)^2\right|_{\alpha=1}\int_a^{b} e^{-\alpha x}dx=\left.\left(\frac{d}{d\alpha}\right)^2\right|_{\alpha=1} \frac{1}{\alpha}(e^{-a\alpha}-e^{-b\alpha}). $$ Of course, this can also be evaluated explicitly by using the Leibniz rule, but I will leave that up to you.