Decomposition for a Sum of Matrix Products I need to find the following matrix decomposition:
\begin{align}
AB+BA-BAB=XX',
\end{align}
where $A$ is a $n\times n$ symmetrical matrix with full rank, $B$ is a $n\times n$ matrix of ones, so it has rank 1, and $X$ is a an $n\times q$ matrix contained in the column-space of an $A$. 
 A: This cannot work without further assumptions on $A$, $B$. If there would be such a decomposition, then the matrix
$$
AB+BA-BAB
$$
would be positive semidefinite.
Consider
$$
A=\pmatrix{1&0\\0&2},\ B=\pmatrix{1&1\\1&1},
$$
then 
$$
AB+BA-BAB=\pmatrix{1&1\\2&2} + \pmatrix{1&2\\1&2} - 3\pmatrix{1&1\\1&1}
= \pmatrix{-1 & 0\\0&1}
$$
where I used $BAB = (e^TAe)\cdot B$, $e=\pmatrix{1 & \dots & 1}^T$, $B=ee^T$.
Clearly, $AB+BA-BAB$ is not positive semidefinite. Thus there does not exist the desired decomposition.
A: As $XX^T$ is always positive semidefinite, we need $C=AB+BA-BAB$ to be positive semidefinite. Let $u$ be the all-one vector and $v=Au-\frac{u^TAu}2u$. Then $C=uv^T+vu^T$. It is known that the eigenvalues of such a matrix are $n-2$ zeros and also the two values
$$
\lambda=u^Tv\pm\sqrt{(u^Tu)(v^Tv)}.\tag{1}
$$
In order that $C$ is positive semidefinite, the two $\lambda$s in $(1)$ must be nonnegative. Since $u$ is a nonzero vector in our case, by $(1)$ and Cauchy-Schwarz inequality, we conclude that $v$ must be a nonnegative scalar multiple of $u$. By the definitions of $u$ and $v$, this means that $Au=ru$ for some number $r$ such that $(n-2)r\le0$. When this condition is satisfied, we have $v=(1-\frac n2)ru$ and $C=(2-n)rB$. Hence $C=xx^T$ where $x=\sqrt{(2-n)r\,}\,u\in\operatorname{ran}(A)$. In particular, when $n=2$, $C$ can be written in the form of $XX^T$ if and only if $C=0$.
