Find the gradient of $f:\Bbb R^m\setminus\{0\}\to\Bbb R,\; x\mapsto |x|$.
Can someone check if the reasoning below is correct? Thank you in advance.
Note: here it is assumed that $|x|=\|x\|_2$. Using directional derivatives I found that (with a slight abuse of notation on vectors)
$$D_vf(x)=\lim_{t\to 0}\frac{f(x+tv)-f(x)}{t}=\lim_{t\to 0}\frac1t\left(\sqrt{\sum_{k=1}^m (x_k+tv_k)^2}-\sqrt{\sum_{k=1}^mx_k^2}\right)\\=\lim_{t\to 0}\frac{\sum_{k=1}^m(x_k+tv_k)v_k}{|x+tv|}=\langle x/|x|,v\rangle$$
where I used L'Hôpital rule in the second step. Thus if the differential of $f$ would exists then $\partial f(x)v=D_vf(x)=\langle x/|x|,v\rangle$, and because the proposed $\partial f(x)$ is a linear function we can conclude that indeed it is the differential of $f$, thus the gradient at any point $x\in\Bbb R^m\setminus\{0\}$ is $x/|x|$.
Sure. This works. Another way to see it is to observe that $$\langle x, x\rangle=\vert x \vert^2\;,$$ where $\langle , \rangle$ is the standard inner product. The gradient operator satisfies the Leibniz rule $$\nabla \langle x, x\rangle=\langle dx,x\rangle+\langle x,dx\rangle=2\langle dx,x\rangle=2x\;.$$ Here $d$ denotes the differential (i.e. jacobian matrix) of a vector valued function and the notation indicates that we're considering $\langle dx,x\rangle$ as a vector quantity whose $i$-th component is the inner product with the $i$-th column of the differential. On the other hand, we also have the chain rule from which $$\nabla\langle x, x\rangle=2\vert x \vert \cdot \nabla \vert x \vert\;,$$ provided $\vert x \vert$ is differentiable (which it is on $\mathbb{R}^m-\{0\}$). Combining, $$\nabla \vert x \vert=x/\vert x \vert\;.$$