# Differentiate matrix product with respect to vectorized form

I am very new to matrix calculus, but I can't seem to figure this out. Suppose $$\pmb{X}$$ is a non-square $$m \times n$$ matrix and $$\pmb{Y}$$ is a symmetrical positive definite $$n \times n$$ matrix that is not a function of $$\pmb{X}$$. I need to differentiate: $$\frac{\partial }{\partial \mathrm{vec}\left( \pmb{X} \right)} \mathrm{vec}\left( \pmb{X} \pmb{Y} \pmb{X}^{\top} \right)$$ which should lead to a $$n^2 \times nm$$ matrix I think. My first thought was to make use of $$\mathrm{vec}\left( \pmb{X} \pmb{Y} \pmb{X}^{\top} \right) = (\pmb{X} \otimes \pmb{X}) \mathrm{vec}(\pmb{Y})$$, but post-multiplying $$\mathrm{vec}(\pmb{Y})$$ with any result of differentiating $$\pmb{X} \otimes \pmb{X}$$ with respect to $$\mathrm{vec}\left( \pmb{X} \right)$$ doesn't seem to give a reult of the right dimensions.

• Differentiating with respect to a function seems to be fraught with issues... – copper.hat Feb 11 '19 at 18:23

Consider the vector \eqalign{ w &= {\rm vec}(XYZ) \cr &= (Z^TY^T\otimes I)\,{\rm vec}(X) &= (Z^T\otimes X)\,{\rm vec}(Y) &= (I\otimes XY)\,{\rm vec}(Z) \cr &= (Z^TY^T\otimes I)\,x &= (Z^T\otimes X)\,y &= (I\otimes XY)\,z \cr } and its differential \eqalign{ dw &= (Z^TY^T\otimes I)\,dx + (Z^T\otimes X)\,dy + (I\otimes XY)\,dz \cr } Now assume $$Y$$ is constant and $$Z=X^T$$, i.e. $$dy=0,\quad dz=K\,dx$$ where $$K$$ is the Commutation Matrix associated with the vec-operation.
Substituting this into the differential expression yields \eqalign{ dw &= \Big(\big(XY^T\otimes I\big) + \big(I\otimes XY\big)K\Big)\,dx \cr \frac{\partial w}{\partial x} &= \big(XY^T\otimes I\big) + \big(I\otimes XY\big)K \cr }