everyone. I have a function \begin{equation} f(B)=\mathbf{a}^H\mathbf{R}(\mathbf{R}+\mathbf{Q})^{-1}\mathbf{R}\mathbf{a}, \end{equation} how to compute the derivative $\frac{\partial f}{\partial B}$, note that $B,\mathbf{a}$ are vectors, $\mathbf{R}$ is a symmetric matrix. And $\mathbf{Q}$ is given by \begin{equation} \mathbf{Q} = \text{diag}\left( \left[\frac{\left(2^{B_1}-1\right)^2}{\mathcal{A}_1^2}, \frac{\left(2^{B_2}-1\right)^2}{\mathcal{A}_2^2},...,\frac{\left(2^{B_M}-1\right)^2}{\mathcal{A}_M^2} \right] \right). \end{equation}
Thanks in advance. Awaiting any response.