<s>[INST] $E(X^2)$ of discrete uniform distribution I have a discrete uniform distribution (from IFoA formulae) with parameters a, b, h, where a and b are the start/end points, and h is the interval between each value. The p.d.f. is given as $\frac{h}{b-a+h}$. I manage to find out $$E[X] = \sum_{x\in X} xf(x) = \sum_{x\in X} \frac{xh}{b-a+h} = \frac{h}{b-a+h}\sum_{x\in X} x\\= \frac{h}{b-a+h}\times \frac{a+b}{2}\times \frac{b-a+h}{h} = \frac{a+b}{2}.$$ However, I cannot figure out the second moment ($E[X^2]$) and Variance by using the same method. I wonder if it is possible to find them using the same way, I know they could be found by using the M.G.F., I just want to know if it is possible.
$Var(X) = \frac{(b-a)(b-a+2h)}{12}$ is given by the formulae.
Here is what I have got so far:
$$\sum_{x\in X} x^2f(x) = \sum_{x\in X} \frac{x^2 h}{b-a+h} = \frac{h}{b-a+h}\sum_{x\in X} x^2=\frac{h}{b-a+h}\sum_{k=0}^{\frac{b-a+h}{h}}(hk+a)^2$$
edit:
\begin{align*}
E[X^2]  &= \sum_{x\in X} x^2f(x)\\
&=\frac{h^3}{b-a+h}\sum_{k=0}^{\frac{b-a+h}{h}}k^2+\frac{2ah^2}{b-a+h}\sum_{k=0}^{\frac{b-a+h}{h}}k+\frac{a^2h}{b-a+h}\sum_{k=0}^{\frac{b-a+h}{h}}1\\
&=\frac{h^3}{b-a+h}\frac{(\frac{b-a}{h})(\frac{b-a}{h}+1)(2(\frac{b-a}{h})+1)}{6}+\frac{2ah^2}{b-a+h}\frac{(\frac{b-a}{h}+1)(\frac{b-a}{h})}{2}+\frac{a^2h}{b-a+h}\bigg(\frac{b-a}{h}+1\bigg)\\
&= \frac{h^3}{b-a+h}\frac{(\frac{b-a}{h})(\frac{b-a+h}{h})(\frac{2(b-a)+h}{h})}{6}+\frac{2ah^2}{b-a+h}\frac{(\frac{b-a+h}{h})(\frac{b-a}{h})}{2}+\frac{a^2h}{b-a+h}\bigg(\frac{b-a+h}{h}\bigg)\\
&= \frac{(b-a)(2(b-a)+h)}{6}+a(b-a)+a^2\\
Var(X)  &= E[X^2] - E[X]^2\\
            &= \frac{(b-a)(2(b-a)+h)}{6}+a(b-a)+a^2 - \bigg(\frac{a+b}{2}\bigg)^2\\
            &= \frac{2(b-a)(2(b-a)+h)+12a(b-a)+12a^2}{12} - \frac{3(a+b)^2}{12}\\
            &= \frac{4b^2-4ab+2bh-4ab+4a^2-2ah+12ab-12a^2+12a^2-3a^2-6ab-3b^2}{12}\\
            &= \frac{(a-b)^2+2h(b-a)}{12} \\
&= \frac{(b-a)^2+2h(b-a)}{12}\\
            &= \frac{(b-a)(b-a+2h)}{12}
\end{align*}
 [/INST] With your edit, you are almost there.  You can simplify 
$$\frac{h}{b-a+h}\sum_{k=0}^{b-a}(hk+a)^2$$
$$=\frac{h}{b-a+h}\sum_{k=0}^{b-a}\left((hk)^2+2ahk+a^2 \right)$$
$$=\frac{h}{b-a+h}\sum_{k=0}^{b-a}(hk)^2+\frac{h}{b-a+h}\sum_{k=0}^{b-a}(2ahk)+\frac{h}{b-a+h}\sum_{k=0}^{b-a}a^2$$
$$=\frac{h^3}{b-a+h}\sum_{k=0}^{b-a}k^2+\frac{2ah^2}{b-a+h}\sum_{k=0}^{b-a}k+\frac{a^2h}{b-a+h}\sum_{k=0}^{b-a}1$$
For the first term you can apply
$$\sum_{x=0}^n x^2 = \frac{n(n+1)(2n+1)}{6}$$
and apply the similar formulas that you did previously for the other 2 terms.
</s>