What should be the gradient of the L2 norm of a linear vector function

I want to compute the gradient of the vector function $f(\vec{x}) = \|\vec{x} - \vec{a}\|$, I have a try, but the result is kind of strange to me.

so here is my steps \begin{align*} \nabla\|\vec{x} - \vec{a}\| & = \nabla\sqrt{\sum_{i = 1}^{n}(x_i - a_i)^2} \\ & = \frac{\nabla \sum_{i = 1}^{n} (x_i - a_i)}{2\sqrt{\sum_{i = 1}^{n}(x_i - a_i)^2}}\\ \end{align*}

since the gradient of $\sum_{i = 1}^{n} (x_i - a_i)$ will give back a vector, so I think this should be really the original vector scaling by 2, $2(\vec{x} - \vec{a})$, and then \begin{align*} \nabla\|\vec{x} - \vec{a}\| & = \frac{\nabla \sum_{i = 1}^{n} (x_i - a_i)}{2\sqrt{\sum_{i = 1}^{n}(x_i - a_i)^2}}\\ & = \frac{2(\vec{x}-\vec{a})}{2\sqrt{\sum_{i = 1}^{n}(x_i - a_i)^2}}\\ & = \frac{\vec{x} - \vec{a}}{\| \vec{x} - \vec{a} \|_2} \end{align*} so it's seems that the gradient of function $f(\vec{x}) = \|\vec{x} - \vec{a}\|$ is really doing the vector normalization? Am I making something mistake at here can someone check this with me?


This is perfectly correct. If you remember the conceptual interpretation of the gradient, it makes good sense: The norm increases most rapidly, and with rate 1, if you move from $x$ radially outward from $a$.