# Differentiation of $\frac{\sum\limits_{i=1}^n |x_i|}{\left(\sum\limits_{i=1}^n x_i^2\right)^{\frac12}}$

Given a vector $X = [x_1, x_2,\ldots,x_n]^T$, how do you differentiate the function $\dfrac{\sum\limits_{i=1}^n |x_i|}{\left(\sum\limits_{i=1}^n x_i^2\right)^{\frac12}}$ with respect to each $x_i$ where $x_i \in [0,1]$

-
If the $x_i$ are positive, then no need for the absolute value, yes? – J. M. Sep 6 '11 at 5:18
Anyway: treat this problem as if you're differentiating $\frac{x+c}{\sqrt{x^2+d}}$ with respect to $x$... – J. M. Sep 6 '11 at 5:19
Write $|x_i|=\mathrm{sgn}(x_i) x_i$, it's not differentiable when $x_i=0$ anyway. Then note $\partial_ir=x_i/r$ and use the quotient rule. – anon Sep 6 '11 at 5:38

Since $\|x\|^2=\sum\limits_{j=1}^nx_i^2$, we get that $\frac{\partial}{\partial x_k}\|x\|^2=2x_k$.
The chain rule says that $\frac{\partial}{\partial x_k}\|x\|^2=2\|x\|\frac{\partial}{\partial x_k}\|x\|$.
Thus, we get that $\frac{\partial}{\partial x_k}\|x\|=\frac{x_k}{\|x\|}$. This also gives that $\frac{\mathrm{d}}{\mathrm{d}x}|x|=\frac{x}{|x|}$.
These and the quotient rule yields $$\frac{\partial}{\partial x_k}\frac{\sum\limits_{i=1}^n |x_i|}{\|x\|}=\frac{\frac{x_k}{|x_k|}\|x\|-\frac{x_k}{\|x\|}\sum\limits_{i=1}^n|x_i|}{\|x\|^2}$$