$$\frac{\partial a^TX a}{\partial X} = \frac{\partial a^TX^T a}{\partial X} = aa^T \tag 1$$
I got (1) from the Matrix Cookbook. But I don't see how you derive it? Why isn't it $a^Ta$.
Assume that $a$ is an arbitrary vector of real numbers of length $n$ and $X$ is an arbitrary $n\times n$ matrix.
Write out $a^TXa$ by component:
$$ a^TXa = \sum_{ij} a_ix_{ij}a_j $$
Realize that $\frac{\partial}{\partial X}$ is shorthand for the matrix composed of entries $\frac{\partial}{\partial x_{ij}}$. Therefore,
$$ \frac{\partial a^TXa}{\partial x_{ij}} = a_ia_j $$
Stack these into a matrix, and this is exactly $aa^T$. Why not $a^Ta$? Just look at the dimensions! :)