# How to differentiate with respect to a matrix?

How can I differentiate the following by $\mathbf{W}$ ?

$$\mathbf{Y} = (\mathbf{W}^T\mathbf{x} + b)^2$$

Where $\mathbf{W} \in \mathcal{R}^{d\times D}$ and $\mathbf(x)\in \mathcal{R}^{d\times 1}$

How to calculate $\partial \mathbf{Y}/\partial \mathbf{W}$ ?

• Can you explain what is the context? In this kind of equations you usually differentiate the vector, and the matrix is constant. – Aksakal Jan 8 '15 at 15:08
• $\mathbf{W}^T\mathbf{x} + b$ does not make any sense. You cannot add a column vector to a scalar. – Rodrigo de Azevedo Oct 14 '16 at 15:56

Matrix calculus is used in such cases. Your equation looks like it's from OLS (least squares) theory. In those you differentiate by vector $x$ some quadratic forms like $\frac{\partial (x'A'Ax)}{\partial x}$. Look up relevant formulae in my link above.