I am trying to understand how matrix derivatives work, focusing myself on the chain rule.
Consider $g(U): \mathbb{R}^{N\text{x}N} \rightarrow \mathbb{R}$, and $U=f(X) : \mathbb{R}^{N\text{x}N} \rightarrow \mathbb{R}^{N\text{x}N}$
Then applying the chain rule I know that:
$\frac{\partial g(U)}{\partial X_{ij}}=\text{Tr}[(\frac{\partial g(U)}{\partial U})^T\frac{\partial U}{\partial X_{ij}}]$
However, what happens if $g(U): \mathbb{R}^{N\text{x}N} \rightarrow ^{N\text{x}N}$. I mean if I have to take the derivative of a matrix w.r.t a matrix. This could appear, for instance, if we have that $U=f(Z) : \mathbb{R}^{N\text{x}N} \rightarrow \mathbb{R}^{N\text{x}N}$ and $Z=f(X) : \mathbb{R}^{N\text{x}N} \rightarrow \mathbb{R}^{N\text{x}N}$, as on of the steps of the chain rule will involve the derivative of $U$ w.r.t $Z$