Recently, I've come accross a situation where I needed to calculate a sum of the following pattern:
$$x^2+(x+1)^2+(x+2)^2+...+(x+n)^2$$
How do I calculate the sum of it?
Recently, I've come accross a situation where I needed to calculate a sum of the following pattern:
$$x^2+(x+1)^2+(x+2)^2+...+(x+n)^2$$
How do I calculate the sum of it?
For any $k, (x + k)^2 = x^2 + 2kx + k^2$. So, $$\begin{align}(x+0)^2 + \cdots + (x+n)^2 &= (x^2 + 2\cdot 0x + 0^2) + (x^2 + 2\cdot 1x + 1^2) + \cdots (x^2 + 2nx + n^2)\\ &= (n+1)x^2 + 2(0 + 1 + \cdots + n)x + (0^2 + 1^2 + \cdots +n^2)\\ &= (n+1)x^2 + n(n+1)x + \frac{n(n+1)(2n+1)}6\end{align}$$
Note that this holds for any $x$, not just integers.