Let $M\in \mathbb{R}^{n\times n}$ be a matrix and $v\in \mathbb{R}^{n\times 1}$ be a vector. $$f(v):\mathbb{R}^{n\times 1} \rightarrow\mathbb{R}^{n\times n}, f(v)=(vv^T+aI)^{-1}P$$ where $\alpha\in \mathbb{R}^+$ is a constant and $P\in \mathbb{R}^{n\times n}$ and $I$ is the identity matrix.
Let $g(v)=\|f(v)-Q\|_F^2$ ,where $Q\in \mathbb{R}^{n\times n}$.
I want to calculate $\frac{\partial{g}}{\partial v}$.
I know $\frac{\partial{g}}{\partial f}=2(f(v)-Q)$.
But I do not know $\frac{\partial{f}}{\partial v}$. Because the range of $f$ is $\mathbb{R}^{n\times n}$. And $v$ is a vector. What's the dimension of $\frac{\partial{f}}{\partial v}$ should be?
The problem with applying the chain rule to matrix problems is it often requires derivatives (which are higher order tensors) for some of the intermediate steps.
It is far easier to work with differentials, since the differential of a matrix/vector is just another matrix/vector, and not a higher order object.
Anyway, define a few symbols to cast the problem into something easier to manipulate.
Let $$ \eqalign { X &= (vv^T+aI) = X^T \cr f &= X^{-1}\cdot P \cr h &= f-Q \cr M &= f\cdot h^T\cdot X^{-1} \cr g &= h:h } $$
We just need one well-known rule for the differential of an inverse to get started: $$ \eqalign { dX^{-1} &= -X^{-1}\cdot dX\cdot X^{-1} \cr } $$
So the differential of g is $$ \eqalign { dg &= 2h:dh \cr &= 2h:df \cr &= 2h:(dX^{-1}\cdot P) \cr &= 2h:(-X^{-1}\cdot dX\cdot X^{-1}\cdot P) \cr &= 2h:(-X^{-1}\cdot dX\cdot f) \cr &= -2X^{-T}\cdot h\cdot f^T:dX \cr &= -2M^T:dX \cr &= -2M^T:d(vv^T) \cr &= -2M^T:(dv\,v^T + v\,dv^T)) \cr &= -2(M + M^T):v\,dv \cr &= -2v^T\cdot(M + M^T)\cdot dv \cr } $$
The above steps used only differentials of vectors/matrices, no higher-order tensors were needed. Now we can identify the derivative as: $$ \eqalign { \frac {\partial g} {\partial v} &= -2v^T\cdot(M + M^T) \cr } $$
The remaining task is to cast the result into a form that you like, e.g. $$ \eqalign { \frac {\partial g} {\partial v} &= -2v^T\cdot\bigg[f\cdot(f^T-Q^T)\cdot X^{-1} + X^{-1}\cdot(f-Q)\cdot f^T\bigg] \cr } $$