Matrix differential of $AA^T $ I need to find the first and second partial derivative of $\dfrac{\partial \|AA^T\|_{F}^2}{\partial A_i}$ where $A$ is a $n$ by $n$ matrix and $A_i$ denote the $\textit{i}^{th}$ row of matrix $A$.$\|A\|_{F}$ means the F norm of matirx A.  I am always confused about how to transform the expression into elements sum and back to matrix form. 
 A: Write down the function in terms of the Frobenius (:) product and take its differential
$$\eqalign{
 f &= AA^T:AA^T \cr\cr
df &= 2\,AA^T:d(AA^T) \cr
   &= 2\,AA^T: 2\,{\rm sym}(dA\,A^T) \cr
   &= 4\,{\rm sym}(AA^T):dA\,A^T \cr
   &= 4\,AA^TA:dA \cr
}$$
So the gradient of the function is
$$\eqalign{
 G &= \frac{\partial f}{\partial A} \cr
   &= 4\,AA^TA \cr
}$$
Now play the same game with the gradient to find the Hessian, but to handle a matrix-by-matrix derivative we'll need to use  vectorization and the Kronecker ($\otimes$) product 
$$\eqalign{
dG &= 4\,(dA\,A^TA +A\,dA^TA +AA^TdA) \cr
{\rm vec}(dG) &= 4\,(A^TA\otimes I + (A^T\otimes A)P + I\otimes AA^T)\,\,{\rm vec}(dA) \cr
dg &= 4\,(A^TA\otimes I + (A^T\otimes A)P + I\otimes AA^T)\,da \cr\cr
 H = \frac{\partial g}{\partial a} &= 4\,(A^TA\otimes I + (A^T\otimes A)P + I\otimes AA^T) \cr
}$$
where $P$ is the permutation matrix which satisfies $${\rm vec}(A^T)=P\,{\rm vec}(A)$$
A: Let $f:A\rightarrow \|AA^T\|_{F}^2=tr((AA^T)^2)=\sum_{j,k}((AA^T)_{j,k})^2=\sum_{j,k}(A_jA_k^T)^2$. Thus $\dfrac{\partial f}{\partial A_i}= \dfrac{\partial g}{\partial A_i}$ where $g=(A_i{A_i}^T)^2+2\sum_{j\not= i}(A_i{A_j}^T)^2$. The derivative is $\dfrac{\partial f}{\partial A_i}:h\in M_{1,n}\rightarrow 2(A_iA_i^T)(2hA_i^T)+2\sum_{j\not= i}2(A_iA_j^T)(hA_j^T)=4\sum_j (A_iA_j^T)(hA_j^T)$ and the gradient is $\nabla_{A_i} (f)=4\sum_j (A_iA_j^T)A_j$.
The second derivative (Hessian) is: $\dfrac{\partial^2 f}{\partial A_i^2}:(h,k)\in (M_{1,n})^2\rightarrow 4(2(kA_i^T)(hA_i^T)+(A_iA_i^T)(hk^T)+\sum_{j\not= i}(kA_j^T)(hA_j^T)$. The associated symmetric matrix $\nabla^2_{A_i}(f)$ is defined by $h\nabla^2_{A_i}(f)k^T=\dfrac{\partial^2 f}{\partial A_i^2}(h,k)$; then $\nabla^2_{A_i}(f)=4(2A_i^TA_i+(A_iA_i^T)I+\sum_{j\not= i}A_j^TA_j)$
that is $\nabla^2_{A_i}(f)=4(\sum_jA_j^TA_j+A_i^TA_i+||A_i||^2I)$.
