TITLE: How to take the gradient of the quadratic form?
QUESTION [64 upvotes]: It's stated that the gradient of:
$$\frac{1}{2}x^TAx - b^Tx +c$$
is 
$$\frac{1}{2}A^Tx + \frac{1}{2}Ax - b$$
How do you grind out this equation? Or specifically, how do you get from $x^TAx$ to $A^Tx + Ax$?

REPLY [8 votes]: I am just writing this answer for future reference and for clarity because the accepted answer is not completely correct and may case confusion.
I will use a simple proof to better understand the multiplication rule in the calculation of $\nabla\mathbf{x^TAx}$.
For $\mathbf{x}\in \mathbb{R}^n$ and $\mathbf{A}\in \mathbb{R}^{n\times n}$ let: $$f(g(\mathbf{x}),h(\mathbf{x}))=\langle g(\mathbf{x}),h(\mathbf{x})\rangle=g^T(\mathbf{x})h(\mathbf{x})$$
Where:
\begin{equation}
\begin{split}
&g(\mathbf{x})=\mathbf{x}\\
&h(\mathbf{x})=\mathbf{Ax}
\end{split}
\end{equation}
From the definition of $f$, it is obvious that $f(g(\mathbf{x}),h(\mathbf{x}))=\mathbf{x^TAx}$.
In order to calculate the derivative, we will use the following fundamental properties, where $\mathbf{I}$ is the identity matrix:
\begin{equation}
\begin{split}
&\dfrac{\partial \mathbf{A^Tx}}{\partial\mathbf{x}}=\dfrac{\partial \mathbf{x^TA}}{\partial\mathbf{x}}=\mathbf{A^T}\\
&\dfrac{\partial \mathbf{x}}{\partial\mathbf{x}}=\mathbf{I}
\end{split}
\end{equation}
Hence, from the multiplication rule (you can see the rule at wikipedia), we got:
\begin{equation}
\begin{split}
\dfrac{df(g(\mathbf{x}),h(\mathbf{x}))}{d\mathbf{x}}&=g^T(\mathbf{x})\dfrac{\partial h(\mathbf{x})}{\partial\mathbf{x}}+h^T(\mathbf{x})\dfrac{\partial g(\mathbf{x})}{\partial\mathbf{x}}=\\
&=\mathbf{x^T}\dfrac{\partial \mathbf{Ax}}{\partial\mathbf{x}}+(\mathbf{Ax})^T\dfrac{\partial \mathbf{x}}{\partial\mathbf{x}}=\\
&=\mathbf{x^TA}+\mathbf{x^TA^TI}=\\
&=\mathbf{x^TA}+\mathbf{x^TA^T}=\\
&=\mathbf{x^T}(\mathbf{A+A^T})
\end{split}
\end{equation}
As a result, from the definition of gradient, we got:
$$
\nabla f=\Bigg(\dfrac{df}{d\mathbf{x}}\Bigg)^T=(\mathbf{x^T}(\mathbf{A+A^T}))^T=(\mathbf{A^T+A})\mathbf{x}
$$
Note: The reason I did the proof this way is to be more generalizable. So you can can plug arbitrary functions $g$ and $h$ and use the above multiplication rule to derive the result.