TITLE: Gradient of 2-norm squared
QUESTION [67 upvotes]: Could someone please provide a proof for why the gradient of the squared $2$-norm of $x$ is equal to $2x$?
$$\nabla\|x\|_2^2 = 2x$$

REPLY [5 votes]: I'm not sure if this is rigorous enough to count as a proof, but an elegant way to obtain derivatives of vector expressions is to use matrix differential calculus.
Let $y = \lVert x \rVert_2^2 = x^{T} x$ with $x \in \mathbb{R}^{n}$.
Using the product rule, the differential of $y$ is
$$
dy = dx^{T} x + x^{T} dx = 2 x^{T} dx
$$
We can then set
$$
dy = \frac{dy}{dx} dx = (\nabla_{x} y)^{T} dx = 2x^{T} dx
$$
where $dy/dx \in \mathbb{R}^{1 \times n}$ is called the derivative (a linear operator) and $\nabla_{x} y \in \mathbb{R}^{n}$ is called the gradient (a vector).
Now we can see $\nabla_{x} y = 2 x$.

If $x$ is complex, the complex derivative does not exist because $z \mapsto |z|^{2}$ is not a holomorphic function.
We can, however, instead consider the real derivatives with respect to the two components of $x$.
Let $x = u + i v$.
With this definition, $y$ is a real function of $u, v \in \mathbb{R}^{n}$ defined by
$$
y = x^* x = (u + i v)^* (u + i v) = u^T u - v^T v
$$
Taking the differential
$$
dy = 2 u^T du - 2 v^T dv = \frac{\partial y}{\partial u} du + \frac{\partial y}{\partial v} dv
$$
and therefore
$$
\nabla_{u} y = 2 u \enspace , \qquad \nabla_{v} y = -2 v
$$

For an introduction to matrix differential calculus, see the lecture of Geoff Gordon on YouTube or the paper on matrix derivatives of Mike Giles.