Gradient of Function I am trying to find the $\nabla F$ with respect to $x_i$ where $F$ is as follows:
$$F(x_0,...,x_n) = c_1\sum_{i=0}^{n}\sum_{j=1}^{k}\frac{1}{||x_i - r_j||_2^2} + c_2\sum_{i=0}^{n-1}||x_{i+1}-x_i||_2^2$$
For clarity I will show my attempts at derivation for each seperate part of the sum.

First part of the sum:
$$c_1\sum_{i=0}^{n}\sum_{j=1}^{k}\frac{1}{||x_i - r_j||_2^2}$$
Since it is with respect to $x_i$ there is only a single contribution from the outer summation (fix the value of i):
$$c_1\sum_{j=1}^k\frac{-2}{(x_i - r_j)^3}$$

As for the second part of the sum:
$$c_2\sum_{i=0}^{n-1}||x_{i+1}-x_i||_2^2$$
If you were to expand the summation there would be 2 terms that contain $x_i$, namely $c_2(||x_{i+1}-x_{i}||_2^2 + ||x_{i}-x_{i-1}||_2^2)$. Because of this all other values are considered constants and don't add anything to the final sum.
Thus the partial derivative with respect to $x_i$ would be:
$$c_2(4x_i - 2x_{i+1} - 2x_{i-1})$$

All together I end up with 
$$\frac{\partial F}{\partial x_i} = c_1(\sum_{j=1}^k\frac{-2}{(x_i - r_j)^3}) + c_2(4x_i - 2x_{i+1} - 2x_{i-1})$$
I am not very confident about my derivation of the 2-norm squared $|| \cdot ||_2^2$, especially when it is the denominator. Does this derivation look correct? If not can somebody please show me where my errors stem from?

The partial derivative $\partial_\alpha = \partial/\partial x_\alpha$ of $F$ is:
\begin{align}
\partial_\alpha F(x_0,\dotsc,x_n) 
&= 
c_1\sum_{i=0}^{n}\sum_{j=1}^{k}\partial_\alpha \frac{1}{\lVert x_i - r_j\rVert_2^2} + 
c_2\sum_{i=0}^{n-1} \partial_\alpha \lVert x_{i+1}-x_i\rVert_2^2 \\
&=
c_1\sum_{i=0}^{n}\sum_{j=1}^{k}(-1) \frac{1}{\lVert x_i - r_j\rVert_2^4} \partial_\alpha \lVert x_i - r_j\rVert_2^2 + 
c_2\sum_{i=0}^{n-1} \partial_\alpha \lVert x_{i+1}-x_i\rVert_2^2 \\
&=
c_1\sum_{i=0}^{n}\sum_{j=1}^{k}(-1) \frac{1}{\lVert x_i - r_j\rVert_2^4} 
2(x_\alpha - r_j) + 
c_2\sum_{i=0}^{n-1} 2 ((x_\alpha - x_{\alpha - 1}) - (x_{\alpha+1} - x_\alpha)) \\
&=
\begin{cases}
-2\left( 
c_1\sum_{i=0}^{n}\sum_{j=1}^{k} \frac{x_\alpha - r_j}{\lVert x_i - r_j\rVert_2^4} + 
c_2\sum_{i=0}^{n-1} (x_{\alpha+1} - x_\alpha) \right) 
&; \alpha = 0 \\
-2\left( 
c_1\sum_{i=0}^{n}\sum_{j=1}^{k} \frac{x_\alpha - r_j}{\lVert x_i - r_j\rVert_2^4} + 
c_2\sum_{i=0}^{n-1} (x_{\alpha+1} - 2x_\alpha + x_{\alpha-1}) \right)
&;  0 < \alpha < n \\
-2\left( 
c_1\sum_{i=0}^{n}\sum_{j=1}^{k} \frac{x_\alpha - r_j}{\lVert x_i - r_j\rVert_2^4} + 
c_2\sum_{i=0}^{n-1} (-x_\alpha + x_{\alpha-1}) \right) 
&; \alpha = n \\
\end{cases}
\end{align}
so we get
$$
\DeclareMathOperator{grad}{grad}
\grad F(x_0,\dotsc,x_n) =
-2\left( 
c_1\sum_{i=0}^{n}\sum_{j=1}^{k} \frac{x - r_j}{\lVert x_i - r_j\rVert_2^4} + 
c_2\sum_{i=0}^{n-1} \sum_{\alpha=0}^n (
\dotsb ) e_\alpha \right)
$$
