# Let $X$ be a random variable uniformly distributed on $[-1,1]$…

Let $X$ be a random variable uniformly distributed on $[-1,1]$. $$f_{X}(x) =\left\{\begin{matrix} \frac{1}{2}, -1 \leq x\leq 1\\ 0 \,\,\,\,\,\, \text{otherwise} \end{matrix}\right.$$ Evaluate the $n$-th moment of $X$, $E[X^{n}]$.

My solution so far: $$E[X^{n}] = \frac{d}{dt^{n}}M_{X}(t) \mbox{ at t= 0}$$ $$M_{X}(t)=E[e^{tx}] = \int_{-\infty}^{\infty}e^{tx}f_{X}(x)dx = \frac{1}{2}\int_{-\infty}^{\infty}e^{tx}dx = \frac{1}{2}\frac{e^{tx}}{t}.$$ $$E[X^{n}] = \frac{1}{2}\frac{e^{0}}{0} = undefined$$ $$E[X^{n}] =\frac{d}{dt^{n}}M_{X}(t)=\frac{e^{0x}}{2} = \frac{1}{2}.$$
I'm not sure if this is the correct answer. Am I doing this right?

• Your $M_X$ is wonky. – user251257 May 15 '18 at 23:11
Moment generating function is not exactly the best way of pursuing this problem. It is simpler to evaluate directly by means of $$EX^n=\int_{-1}^1 x^nf(x)\, dx=\frac{1}{2}\int_{-1}^1 x^n\, dx$$ For your approach, note that $$M(t)=Ee^{tX}=\int_{-1}^1e^{tx}\frac{1}{2}=\frac{1}{2}\left[\frac{1}{t}e^{tx}\right]_{x=-1}^1=\frac{1}{2t}(e^{t}-e^{-t})=\sum_{k=0}^\infty\frac{1-(-1)^{k+1}}{2(k+1)}\frac{t^{k}}{k!}$$ where the bounds are from $-1$ to $1$ since the density vanishes outside this region. Differentiating the rational function $n$ times and finding it's value at $t=0$ (by means of L'hopital since the resulting discontinuity will be removable) is a pain. Alternatively one can expand as a power series as I did and extract the coefficient of $t^n/n!$ which is simpler but not as simple as computing the integral.
• Doing it the first way you mentioned would get $$\frac{1}{2}\frac{(1)^{n}+(-1)^{n}}{n+1}$$, which is different than what I got above. Why is that? – beepboopbeepboop May 15 '18 at 23:36
$$E[X^n]=2^{-1}\int_{-1}^1 x^n dx$$.