I'm trying to find the second central moment of an exponential random variable, and came across this particular solution provided by the school, which I'm unsure of how the method is possible.
It goes like this: $$E(X^2) = \int^{\infty}_{0} x^2 \lambda{e^{-x\lambda}} dx= \int^{\infty}_{0}x^2 d(-e^{-x\lambda})$$ $$=[-x^2e^{-x\lambda}]^\infty_0 + 2\int^{\infty}_{0}x{e^{-x\lambda}}dx = \frac{2}{\lambda^2}$$
May I know how how exactly is the first line possible? How can I merely interchange $x$ in $dx$ for $-e^{-x\lambda}$? I understand how to find the first central moment by integration by parts, but this baffles me. Any tips and pointers would be much appreciated! Thank you!
It can be useful to calculate these moments in a general case, invoking Gamma Function
$$E(X^k)=\int_0^{\infty} x^k \lambda e^{-\lambda x}dx=\frac{1}{\lambda^k}\int_0^{\infty}(\lambda x)^k e^{-\lambda x} d(\lambda x)=\frac{\Gamma(k+1)}{\lambda^k}=\frac{k!}{\lambda^k}$$
Thus if you have to calculate, i.e., $E(X^{100})$ you can easy derive the solution... instead of doing 100 times by part you integral