Differentiation w.r.t. a matrix I have the scalar $a^TK_P^TK_Pa+b^TK_Pa$, where $a$ and $b$ are known user defined $3*1$ real valued vectors and $K_P$ is an unknown real valued $3*3$ matrix. Could anyone let me know how to express the derivative w.r.t $K_P$ result simply? In literature, I could only find formulae for scalars of the form $trace(f(K_P))$ or $det(f(K_P))$ when they are differentiated by matrices. Can this differentiation too be written in a simple manner? If so, how?  
 A: $\def\s{\operatorname{Sym}}\def\p{{\partial}}\def\grad#1#2{\frac{\p #1}{\p #2}}\def\hess#1#2#3{\frac{\p^2 #1}{\p #2\,\p #3^T}}$For
typing convenience, define the matrices
$$A=aa^T \qquad\quad B=ba^T$$
and use a colon to denote the trace/Frobenius product
$$\eqalign{
A:B &= \sum_{i=1}^m \sum_{j=1}^n A_{ij} B_{ij} \;=\; {\rm Tr}(AB^T) \\
A:A &= \big\|A\big\|_F^2 \\
}$$
Write the function using the above notation, then calculate its differential and gradient.
$$\eqalign{
\phi &= A:K^TK + B:K \\
d\phi &= A:(K^TdK+dK^TK) + B:dK \\
 &= (A+A^T):K^TdK + B:dK \\
 &= (2KA+B):dK \\
\grad{\phi}{K} &= 2KA+B \\
 &= (2Ka+b)a^T \\
}$$
A: The function $F \colon \mathbb R^{n^2} \to \mathbb R$is $F(K)=a^TK^TKa+b^TKa$. If we can write $F(K + H)$ as $F(K)+D(K)H + \phi(H)$ for some linear operator $D(K): \mathbb R^{n^2} \to \mathbb R$ and function $\phi$ that goes to zero faster than $H$ then $D(K)$ wil be the derivative at the point $K$. So let's see. . . 
$F(K+H)=a^T(K+H)^T(K+H)a+b^T(K+H)a$
$ = a^T(K^T+H^T)(K+H)a+b^T(K+H)a$
$ = a^T K^T K a + a^T K^T H a + a^T H^T K a + a^T H^T H a + b^TKa + b^THa$
$ = (a^T K^T K a + b^TKa )+ a^T K^T H a + a^T H^T K a + a^T H^T H a + b^THa$
$ = F(K)+ a^T K^T H a + a^T H^T K a + a^T H^T H a + b^THa$
$ = F(K)+ (a^T K^T H a + a^T H^T K a + b^THa) + a^T H^T H a$ 
The second part $(a^T K^T H a + a^T H^T K a + b^THa)$ is a linear operator in $H$ and the second  shrinks fast enough. So we have $D(K) = (a^T K^T H a + a^T H^T K a + b^THa)$.
Edit: $D(K)$ is a linear operator that takes $H$ as input and gives $a^T K^T H a + a^T H^T K a + b^THa$ as output. $K$ determines which point we are taking the derivative at. $H$ determines which direction we are taking the derivative along.
A: The answer to your first question is yes.
The answer to your second question is $2K_Paa^T+ba^T$ is the derivative.
To see this note that your expression can be rewritten in the following form.
$$\text{tr}\left(\left(K_Paa^T+ba^T\right)K_P^T\right)$$
Then we have the following. (After some manipulation.)
\begin{align}\text{tr}\left(\left((K_P+H)aa^T+ba^T\right)(K_P^T+H^T)\right)= \;&\text{tr}\left(\left(K_Paa^T+ba^T\right)K_P^T\right)+\text{tr}\left(\left(2K_Paa^T+ba^T\right)H^T\right)\\&+\text{tr}\left(Haa^TH^T\right)\end{align}
