# How to get the gradient of a matrix product with respect to a vector?

I am new to vector calculus and even though I was able to understand how to derive simpler functions like the product of two vectors in $\mathbb{R}^m$, I am confused about this specific scenario.

Lets say we have a column vector $x \in \mathbb{R}^m, A \in \mathbb{R}^{m\times m}$.

How can I determine the gradient of $x^TA$ with respect to $x$?

I am not able to grasp how you derive something with respect to a vector.

From what I can see $x^TA$ is equal to $[A_1 \cdot x$, $A_2 \cdot x$, ..., $A_m \cdot x]$ for all columns of $A$. Which means the operation yields a row vector in $\mathbb{R}^m$.

I tried to derive this solution with respect to the individual scalars of $x$ but I am lost since I am clearly not approaching it correctly.

How would one solve this?

• Do all partial derivatives of all components of the vector function you just defined, no? – ir7 Feb 9 '18 at 13:09
• Also, look up Jacobian, as generalization of gradient. – ir7 Feb 9 '18 at 13:23

If you now look at $x^TA$ as a linear map $\mathbb{R}^m\to \mathbb{R}^m$ as $$f(x_1,\ldots, x_m)=(\sum_{i=1}^m a_{i1}x_i,\ldots,\sum_{i=1}^m a_{im}x_i)$$ so we don't have to think about $f$ in columns and rows or matrices, we know that the gradient of the linear map is written as $$\frac{\partial f}{\partial x}=\left(\begin{array} \ a_{11} & a_{21} & \dots & a_{m1} \\ a_{12} & a_{22} & \dots & a_{m2} \\ \vdots & \vdots & \ddots & \vdots \\ a_{1m} & a_{2m} & \dots & a_{mm} \end{array}\right)=A^T$$ by convention of derivatives are from left to right and $f$-elements from the top down.