Derivative of matrix-valued function with respect to scalar Given vector $\mu \in \Bbb R^n$ and $n \times n$ matrices $A$ and $\Sigma$, let matrix-valued function $F : \Bbb R \to \Bbb R^{n \times n}$ be defined by
$$F(t) := |(I-2tA\Sigma)|^{1/2} \exp \left(\frac{1}{2}\mu'[I-(I-2tA\Sigma)^{-1})\Sigma^{-1}\mu \right)$$
How can I get the second derivative of $F$ with respect to $t$? Could someone please give me a hint?
 A: Try matrixcalculus.org. Entering
det(eye-2*t*A*S)^(1/2)*exp((1/2) * v'*(eye-inv(eye-2*t*A*S)*inv(S))*v)
yields
function:
$$
  f = \mathrm{det}(\mathbb{I}-2\cdot t\cdot A\cdot S)^{(1/2)}\cdot \exp(1/2\cdot v^\top \cdot (\mathbb{I}-\mathrm{inv}(\mathbb{I}-2\cdot t\cdot A\cdot S)\cdot \mathrm{inv}(S))\cdot v)
$$
gradient:
$$\begin{aligned}
 \frac{\partial f}{\partial t} = 
&-(\mathrm{det}(\mathbb{I}-2\cdot t\cdot A\cdot S)^{(1/2-1)}\cdot \exp((v^\top \cdot (\mathbb{I}-\mathrm{inv}(\mathbb{I}-2\cdot t\cdot A\cdot S)\cdot \mathrm{inv}(S))\cdot v)/2)\cdot \mathrm{tr}(A\cdot S\cdot \mathrm{adj}(\mathbb{I}-2\cdot t\cdot A\cdot S))
\\&+\mathrm{det}(\mathbb{I}-2\cdot t\cdot A\cdot S)^{(1/2)}\cdot \exp((v^\top \cdot (\mathbb{I}-\mathrm{inv}(\mathbb{I}-2\cdot t\cdot A\cdot S)\cdot \mathrm{inv}(S))\cdot v)/2)\cdot v^\top \cdot \mathrm{inv}(\mathbb{I}-2\cdot t\cdot A\cdot S)\cdot A\cdot S\cdot \mathrm{inv}(\mathbb{I}-2\cdot t\cdot A\cdot S)\cdot \mathrm{inv}(S)\cdot v)
\end{aligned}$$
You can try plugging this result back into the engine.
A: For typing convenience, define the matrices
$$\eqalign{
W &= \mu\mu^T,\qquad&S &= \Sigma^T \\
B &= I - 2tAS^T,\qquad &M &= B^{-1}AS^T\\
\dot B &= -2AS^T = -2BM,\qquad&\dot M &= -B^{-1}\dot BB^{-1}AS^T = 2M^2 \\
\dot B^{-1} &= -B^{-1}\dot BB^{-1} = 2MB^{-1} \\
}$$
and the scalars
$$\eqalign{
X &= \tfrac 12WS^{-1}:(I-B^{-1}) \\
\dot X &= \tfrac 12WS^{-1}:(-\dot B^{-1}) 
  = -WS^{-1}:MB^{-1} \\
\\
E &= \exp(X) \\
\dot E &= E \dot X \\
\\
F &= E\;(\det B)^{1/2} \\
L &= \log F 
   = \log(E) + \tfrac 12\log(\det B) 
   = X + \tfrac 12{\rm Tr}(\log(B)) \\
\dot L &= \dot X + \tfrac 12 B^{-T}:\dot B 
\;=\; -(WS^{-1} + B^T):MB^{-1} \\
}$$
So the first derivative of $F$ is
$$\eqalign{
\def\FF{\left(\frac{\dot F}{F}\right)}
\def\B{B^{-1}}
\def\DB{\dot B^{-1}}
\def\S{S^{-1}}
\def\a{\alpha}
\dot L &= \FF \quad&\implies &\dot F = -F\;(W\S + B^T):M\B \\
\dot F &= F\a &\implies\quad &\a = \FF = -(W\S + B^T):M\B \\
}$$
Now the second derivative of $F$ can be calculated.
$$\eqalign{
\ddot F &= \dot F\a + F\dot\a \\
\\
\frac{\ddot F}{F} &= \FF\a + \dot\a \\
 &= \a^2  - (W\S+B^T):(\dot M\B+M\DB) \;-\; (\dot B)^T:(M\B) \\
 &= \a^2 - 2(W\S + B^T):(M^2\B+M^2\B) \;+\; 2(BM)^T:(M\B) \\
 &= \a^2 - 4(W\S + B^T):(M^2\B) \;+\; 2B^T:(M^2\B) \\
 &= \a^2 - \Big(4W\S+2B^T\Big):\Big(M^2\B\Big) 
\\\\
}$$
In several of the steps above, a colon is used to denote the trace/Frobenius product, i.e.
$$\eqalign{ A:B = {\rm Tr}(A^TB) = {\rm Tr}(B^TA) = B:A }$$
