Random variable of probability density function of X is
${f}_{X}(x)=\frac{1}{2},0\le x\le 1\phantom{\rule{0ex}{0ex}} $
${f}_{X}(x)=\frac{1}{4},3\le x\le 5$
Find moment generating function ${M}_{Y}(t)$ of $Y=\left|X-2\right|$ and from here find $E(Y)$.
Here is my solution: ${M}_{Y}(t)=E\left[{e}^{tY}\right]=E\left[{e}^{t\left|X-2\right|}\right]=\int _{0}^{1}\frac{1}{2}{e}^{t(x-2)}dx+\int _{3}^{5}\frac{1}{4}{e}^{t(x-2)}dx=\frac{1}{4t}(2{e}^{-t}-2{e}^{-2t}+{e}^{3t}-{e}^{t})$
I want to use formula $E\left[Y\right]=\frac{d({M}_{Y}(t))}{dt}(t=0)$ to find expected value $E\left[Y\right]$ , but ${M}_{Y}(t)$ will be undefined when $t=0$.
How can I calculate that? Any help will be appreciated.
Your formula for the MGF is valid only for $t \neq 0$. For $t=0$ we have $M_Y(t)=Ee^{0X}=e^{0}=1$. With this value at $0$ $M_Y$ is actually continuous and even continuously differentiable at $0$.
Now $M_Y'(t)=\frac {(4t)(-2e^{-t}+4e^{-2t}+3e^{3t}-e^{t})-4 (2e^{-t}-2e^{-2t}+e^{3t}-e^{t})} {16t^{2}}$ and $M_Y'(0)$ is the limiting value of this at $0$. Using the fact that $e^{ct}\sim 1+ct+c^{2}t^{2}/2$ for $t$ near $0$ you can compute this limit.