Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've got a function $g(x,y) = || f(x,y) ||_2 $ and I want to calculate its derivatives with respect to $x$ and $y$.

Using Mathematica, differentiating wrt $x$ gives me $ f'_x(x,y) \text{Norm}'( f(x,y))$, where Norm is $|| \ldots ||$.

I read here that $d||{\bf x}|| = \frac{ {\bf x}^Td{\bf x}}{||{\bf x}||}$ (at least for 2-norm)

Point is, as inside the norm I have a multivariate function, I'm still confused on how to calculate $ f'_x(x,y) \text{Norm}'( f(x,y))$

I think it should be $f'_x(x,y) \frac{f(x,y)}{||f(x,y)||}$, but some verification would be great :)

share|cite|improve this question
When you are not sure, writing out all components should help. It's nasty, I know, but it always works. – Tunococ Jan 31 '13 at 12:30
First find the derivative of $h(x,y) = \|f(x,y)\|^2 = f(x,y) \cdot f(x,y)$, using the product rule. Then you can get the derivative of $g(x,y) = \sqrt{h(x,y)}$ from the chain rule. – Hans Engler Jan 31 '13 at 12:36
Just saw your edit. This answer is correct. – Hans Engler Jan 31 '13 at 12:36
Thanks for the answer Hans! – Babis Jan 31 '13 at 13:16
up vote 3 down vote accepted

Suppose $f:\mathbb R^m \to \mathbb R^n$. Decompose into $f = (f_1, \ldots, f_n)$. Each $f_i$ is a real-valued function, i.e., $f_i: \mathbb R^m \to \mathbb R$. Then $$ g(X) = \|f(X)\|_2 = \sqrt{\sum_{i=1}^n f_i(X)^2}. $$ Therefore, $$\nabla g(X) = \frac 12\left(\sum_{i=1}^n f_i(X)^2\right)^{-\frac 12}\left(\sum_{i=1}^n 2f_i(X)\nabla f_i(X)\right) = \frac{\sum_{i=1}^n f_i(X)\nabla f_i(X)}{\|f(X)\|_2}. $$ This matches your answer.

If you want to write in terms of the Jacobian matrix of $f$ instead of components $f_i$, you can: $$ \nabla g(X) = \frac{J_f(X)^T f(X)}{\|f(X)\|_2}. $$

share|cite|improve this answer
Many thanks for the answer! – Babis Jan 31 '13 at 13:14

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.