I know that the closed-form of $\sum_{i=1}^n i^2$ is $n(n+1)(2n+1)/6$.
But how to derive the formula through integration? My attempt is
$$ \sum_{i=1}^n i = \frac{n^2+n}{2}\\ \frac{1}{2}\sum_{i=1}^n i^2 = \frac{n^3}{6}+\frac{n^2}{4}\\ \sum_{i=1}^n i^2 = \frac{n^3}{3}+\frac{n^2}{2}\\ $$ My result is obviously not true, but why? Is there a way to derive the formula through integration?
Thank you for your effort!
The continuous function $\frac{n(n+1)}{2}$ is not the same as the discrete sum, as shown in the image.
Warning: the steps below are not justified, but they happen to work.
How about differentiating $\sum_{i=1}^n i^3$ ?
$$\sum_{i=1}^n i^3 = \left(\frac{1}{2}n(n+1) \right)^2$$ $$\Rightarrow \frac{d}{dn} \sum_{i=1}^n i^3 = \frac{1}{4}\left((2n+1)(n)(n+1)+n(n+1)(2n+1) \right) \tag{product rule}$$ $$\Rightarrow 3 \sum_{i=1}^n i^2 = \frac{1}{2}(n)(n+1)(2n+1)$$ $$\Rightarrow\sum_{i=1}^n i^2 = \frac{1}{6}(n)(n+1)(2n+1)$$
as if by magic.