<s>[INST] How to calculate $\int_a^bx^2 dx$ using summation? So for this case, we divide it to $n$ partitions and so the width of each partition is $\frac{b-a}{n}$ and the height is $f(x)$.  
\begin{align}
x_0&=a\\
x_1&=a+\frac{b-a}{n}\\
&\ldots\\
x_{i-1}&=a+(i-1)\frac{b-a}{n}\\
x_i&=a+i\frac{b-a}{n}
\end{align} 
So I pick left point, which is $x_{i-1}$
I start with 
\begin{align}
\sum\limits_{i=1}^{n} \frac{b-a}{n}f\left(a+\frac{(i-1)(b-a)}{n}\right)
&=\frac{b-a}{n}\sum\limits_{i=1}^{n} \left(a+\frac{(i-1)(b-a)}{n}\right)^2\\ 
&=\frac{b-a}{n}\left(na^2+ \frac{2a(b-a)}{n}\sum\limits_{i=1}^{n}(i-1)+\frac{(b-a)^2}{n^2} \sum\limits_{i=1}^{n}(i-1)^2\right)
\end{align}
Here I am stuck because I don't know what$ \sum\limits_{i=1}^{n}(i-1)^2$is (feel like it diverges). Could someone help?
 [/INST] $$\sum_{i=1}^n (i-1)^2$$
$$=\sum_{i=1}^n (i^2-2i+1)$$
$$=\sum_{i=1}^n i^2-2\sum_{i=1}^ni+\sum_{i=1}^n1$$
$$=\frac{n(n+1)(2n+1)}{6}-2\cdot \frac{n(n+1)}{2}+n$$
$$=\frac{(n^2+n)(2n+1)}{6}-n(n+1)+n$$
$$=\frac{2n^3+3n^2+n}{6}-n^2$$
$$=\frac{2n^3-3n^2+n}{6}$$
$$=\frac{n(n-1)(2n-1)}{6}$$
</s>