1
$\begingroup$

The problem

I'd like to ask if I differentiated the following function $F(\boldsymbol a)$ correctly:

$$ F(\boldsymbol a) = \lVert \boldsymbol P(\boldsymbol a) - \boldsymbol b \rVert^2 \\ \frac{\partial F}{\partial \boldsymbol a} = \ ? $$

where

$$\begin{align} \boldsymbol a, \boldsymbol b &\in \mathbb R^{3}\\ \boldsymbol P&: \mathbb R^{3} \to \mathbb R^{3}\\ F&: \mathbb R^{3} \to \mathbb R \end{align} $$

and $\lVert \cdot\rVert^2$ is the squared norm (dot product).

My attempt to solution

I proceeded by writing the dot product explicitly and differentiating w.r.t. each of the 3 components of $\boldsymbol a$:

$$\begin{align} F(\boldsymbol a) &= (\boldsymbol P_1(\boldsymbol a) - b_1)^2 + (\boldsymbol P_2(\boldsymbol a) - b_2)^2 + (\boldsymbol P_3(\boldsymbol a) - b_3)^2\\ % % \frac{\partial F}{\partial \boldsymbol a} &= \begin{bmatrix} \partial_{\boldsymbol a1}\ F(\boldsymbol a)\\ \partial_{\boldsymbol a2}\ F(\boldsymbol a)\\ \partial_{\boldsymbol a3}\ F(\boldsymbol a) \end{bmatrix} \end{align}$$

where $b_i$ is the $i$-th component of $\boldsymbol b$ (analogously for $\boldsymbol a$), and $\boldsymbol P_i(\boldsymbol a)$ is the $i$-th component of the vector $\boldsymbol P(\boldsymbol a)$.

The partial derivative of $F$ by $\boldsymbol a$'s component $i$: $$\begin{align} \partial_{\boldsymbol ai}\ F(\boldsymbol a) &= 2(\boldsymbol P_i(\boldsymbol a) - b_i)\cdot \frac{\partial \boldsymbol P_i}{\partial \boldsymbol a}(\boldsymbol a)\cdot \frac{\partial \boldsymbol a}{\partial a_i}(\boldsymbol a)\\ &= 2(\boldsymbol P_i(\boldsymbol a) - b_i)\cdot \frac{\partial \boldsymbol P_i}{\partial a_i}(\boldsymbol a) \end{align}$$

I could then rewrite $\frac{\partial F}{\partial \boldsymbol a}$ as:

$$\begin{align} \frac{\partial F}{\partial \boldsymbol a} = 2\boldsymbol M(\boldsymbol P(\boldsymbol a) - \boldsymbol b) \end{align}$$

where $\boldsymbol M$ is the diagonal-matrix created from $\nabla \boldsymbol P(\boldsymbol a)$.

1 Answers 1

3

For typing convenience let $$\eqalign{ J &= \frac{\partial P}{\partial a} \,\,\implies \,\, J_{ij} &= \frac{\partial P_i}{\partial a_j} \cr }$$

Find the differential of $F$ and then its gradient $$\eqalign{ F &= (P-b)\cdot(P-b) \cr\cr dF &= 2(P-b)\cdot dP \cr &= 2(P-b)\cdot(J\cdot da) \cr &= \Big[2J^T\cdot(P-b)\Big]\cdot da \cr\cr \frac{\partial F}{\partial a} &= 2J^T\cdot(P-b) \cr\cr }$$ There's no reason to create a diagonal matrix $M$, use the full $J$ matrix.

  • 0
    Thank you! Is it a common approach to first find the differential and then work out the derivative? I'm sorry, I have no experience with matrix calculus. Do you know of any great book/study material on this topic (matrix calculus (maybe with einstein's summation notation))?2017-02-26