Chain rule for derivative of matrix-valued function

derivativesmatricespartial derivative

Hi I have the following problem:

Let $x=x(t),a\in R^2$ with scalar $t$ and $\dot x=\frac{dx}{dt}$. Let the matrix-valued function, $f$, be
$$f(x(t))=x(t)x(t)^T+Ie^{\|a-x\|^2},$$ with $I$ being the identity matrix.
What is the derivative $\frac{df(x)}{dt}$?

My best try for the first term so far is evaluating the matrix column-wise, similar to a vector-valued function:
$$\frac{dxx^T}{dt}=\frac{d}{dt}\left(\begin{bmatrix}x_1^2&x_1x_2\\x_1x_2&x_2^2\end{bmatrix}\right)=\begin{bmatrix}\begin{bmatrix}2x_1&0\\x_1&x_2\end{bmatrix}\begin{bmatrix}\dot x_1\\\dot x_2\end{bmatrix}& \begin{bmatrix}x_1&x_2\\0&2x_2\end{bmatrix}\begin{bmatrix}\dot x_1\\\dot x_2\end{bmatrix}\end{bmatrix}.$$

I am not sure if this is correct and how to differentiate the second term. Help is much appreciated! Thanks.

Best Answer

You're slightly off for the derivative of the first term. Use the chain rule on each component to see that $$\frac{d}{dt} xx^\intercal = \begin{bmatrix} \begin{matrix} 2x_1\dot x_1 & \dot x_1 x_2 + x_1 \dot x_2 \\ \dot x_1 x_2 + x_1 \dot x_2 & 2x_2\dot x_2 \end{matrix} \end{bmatrix}. $$

Factoring each column gives $$ \begin{bmatrix}\begin{bmatrix}2x_1&0\\x_2&x_1\end{bmatrix}\begin{bmatrix}\dot x_1\\\dot x_2\end{bmatrix}& \begin{bmatrix}x_2&x_1\\0&2x_2\end{bmatrix}\begin{bmatrix}\dot x_1\\\dot x_2\end{bmatrix}\end{bmatrix}, $$ which is very close to what you had. It is not clear to me why you would perform this factorization though. I prefer $$ \frac{d}{dt} xx^\intercal = \dot x x^\intercal + x \dot x^\intercal $$ as an alternative form.

Now the second term. Recall that $||a - x||^2 = (a_1 - x_1)^2 + (a_2 - x_2)^2$. Using the multivariate chain rule, $\frac{d}{dt} ||a - x||^2 = \dot x_1\frac{d}{dx_1} ||a - x||^2 + \dot x_2\frac{d}{dx_2} ||a - x||^2 = \dot x_1(2x_1 - 2a_1) + \dot x_1(2x_1 - 2a_1) = 2\dot x^\intercal (x - a).$

Then we can apply the chain rule again to get the derivative of the second term,

$$ \frac{d}{dt} I e^{||a - x||^2} = Ie^{||a - x||^2} \cdot 2\dot x^\intercal (x - a). $$