Given is the function $f : \mathbb{R}^p \to \mathbb{R}$ with
$$ f(x) = q(x)^{\top} G^{-1} q(x) $$
where $G = A + x_1 B_1 + \ldots + x_p B_p$.
The matrices $A, B_1, \ldots, B_p \in \mathbb{R}^{n \times n}$ are all symmetric positive definit.
$q: \mathbb{R}^n \to \mathbb{R}^n$ and the Jacobian $\nabla q$ is known.
Is it possible to derive a closed form for $\nabla f$? For me, the hard part is $G^{-1}$. Any hints or suggestions are really appreciated!
$$\frac1{\Delta x}\big[(A+(x+\Delta x)B)^{-1}-(A+xB)^{-1}\big]=$$ $$\frac1{\Delta x}(A+xB)^{-1}(A+xB)\big[(A+(x+\Delta x)B)^{-1}-(A+xB)^{-1}\big] (A+(x+\Delta x)B) (A+(x+\Delta x)B)^{-1}$$ $$=-(A+xB)^{-1}B (A+(x+\Delta x)B)^{-1}\rightarrow-(A+xB)^{-1}B(A+xB)^{-1}$$ as $\Delta x\rightarrow0$.
So that $\partial f/\partial x_j=2\partial q/\partial x_j^\top G^{-1} q -q^\top G^{-1}B_jG^{-1}q$.