TITLE: Differentiating a constant and switching order
QUESTION [7 upvotes]: Why does this work?
$$\int x^2e^{ax}dx = \int \frac{d^2}{da^2}e^{ax}dx = \frac{d^2}{da^2}\int e^{ax}dx = \frac {d^2}{da^2} \frac {e^{ax}}a = \frac{e^{ax}(a^2x^2-2ax+2)}{a^3}$$
$a$ is a constant, so how can you take the derivative with respect to it?  Also, why can you just switch the order of integration with differentiation?  We did this is physics, but what's the justification?  Will this type of thing always work?

REPLY [2 votes]: Physicists love doing this. I would not hesitate in saying this almost always works. You are right that $a$ is a constant but it is also true that if $a$ were treated as a variable, the statement $$ x^2 e^{ax} = \frac {\mathrm{d}^2}{\mathrm{d}a^2} e^{ax} $$ is true. As for differentiating under the integral sign, see a full explanation here.