Is the gradient of this summation correct? Consider the following summation:
$$f(P_e,P_R) = \sum\limits_{i \neq R}\left(\delta_{i}-h(P_{e},P_{R},P_{i})\right)^2$$
where $\delta_{i}$ is a real number and $h$ is the function:
$$h(P_{e},P_{R},P_{i}) = \|P_R - P_e\|_2 - \|P_i - P_e\|_2$$
where the $P_e$, $P_R$ and $P_i$ are points on the Cartesian 3-D space.
I need to use the gradient on a steepest descent algorithm, since I
want to minimize $f$ along $P_e$ (other variables are fixed). 
I have calculated the following:
$$\nabla f(P_e,P_R) = 2\sum\limits_{i \neq R}(\delta_{i}-h(P_{e},P_{R},P_{i}))\nabla h(P_e,P_R,P_i)$$
and,
$$\nabla h(P_e,P_R,P_i) = \frac{P_e - P_R}{\|P_R - P_e\|_2} - \frac{P_e - P_i}{\|P_i - P_e\|_2}$$
Unfortunately, this doesn't seem to be working.
NOTE - Just noticed that my $\nabla h$ is considerably wrong, as it only finds the derivates of the $P_e$ variables ($(X_e,Y_e,Z_e)$). Still, I don't really want to use the other derivates, since $P_R$ and all the $P_i$ points are fixed in my problem.
 A: Let $P_e^k$ represent the $k$th coordinate of $P_e$. Writing $f$ and $h$ as only depending on $P_e^k$, we have
$$f(P_e^1, \ldots, P_e^n) = \sum\limits_{i \neq R}\left(\delta_{i}-h(P_e^1, \ldots, P_e^n)\right)^2,$$
where
$$h(P_e^1, \ldots, P_e^n) = \sqrt{\sum_l (P_R^l - P_e^l)^2} - \sqrt{\sum_l (P_e^l - P_i^l)^2}.$$
Thus,
\begin{align}
\frac{\partial f}{\partial P_e^k} & = \sum_{i\neq R} 2\left(\delta_{i}-h(P_e^1, \ldots, P_e^n)\right)\frac{\partial h}{\partial P_e^k} \\
& = 2\sum_{i\neq R} \left(\delta_{i}-h(P_e^1, \ldots, P_e^n)\right)\left(\frac{-P_R^k + P_e^k}{\sqrt{\sum_l (P_R^l - P_e^l)^2}} - \frac{P_i^k + P_e^k}{\sqrt{\sum_l (P_e^l - P_i^l)^2}}\right).
\end{align}
So yes, the answer is correct.
Another way to look at it is through the multivariate chain rule. In this case we have $u:\mathbb{R}\to \mathbb{R}$, and $v:\mathbb{R}^n\to \mathbb{R}$, with $u(x) = \sum(\delta_i - x)^2$ and $v(\mathbf{x}) = h(P_R, \mathbf{x}, P_i)$.
The chain rule states that $D_\mathbf{a}(u \circ v) = D_{v(\mathbf{a})}u \cdot D_\mathbf{a}v$. In this case, $\mathbf{a} = P_e$ which leads to
\begin{align}
D_{v(\mathbf{a})}u & = 2\sum_{i\neq R} \left(\delta_{i}-v(\mathbf{a})\right)\\
& = 2\sum_{i\neq R} \left(\delta_{i}-h(P_R, P_e, P_i\right)
\end{align}
and
\begin{align}
D_\mathbf{a}v = \nabla_{P_e} h(P_R, P_e, P_i).
\end{align}
