Solving for a matrix in an equation with trace I want to solve the following equation for the $m\times m$ matrix $X$:
$$2X^T(A^TA)=-2\mathrm{trace}(X)I+V,$$
where $I$ is the identity matrix, $A$ is a $t\times m$ known matrix, and $V$ is an $m\times m$ known matrix. Assume that $t$ is less than $m$ so, in this case, $A^TA$ is a singular matrix. 
I looked at the question in 
Solving matrix equation involving trace 
but it did not help me because of the singularity of $A^TA$. 
Also, in the same link, they that said this kind of equations can be solve with vectorization. I searched the internet but could not find anything about this topic: could someone help me with that please? 
Thank you.
 A: Define the variables 
$$\eqalign{
B &= A^TA \cr
W &= \tfrac{1}{2}V^T \cr
\tau &= {\rm tr}(X) \cr
}$$
Divide your equation by $2$ and transpose it 
$$\eqalign{
 BX &= W - \tau I \cr
}$$
The general solution of this linear equation can be written in terms of the Moore-Penrose inverse $B^+$ and the nullspace projector applied to an arbitrary matrix $Y$. 
$$\eqalign{
 X_s &= B^+(W-\tau I) + (I-B^+B)Y \cr
}$$
Be aware that your equation might not have any solutions.
To see this, multiply each side by the transposed projector.
$$\eqalign{
 (I-BB^+)(BX) &= (I-BB^+)(W - \tau I) \cr
  0 &= (I-BB^+)W - \tau (I-BB^+) \cr
  (I-BB^+)W &= \tau (I-BB^+) \\
  V(I-B^+B) &= (2\tau) (I-B^+B) \cr
}$$
A solution only exists when $W$ or $V$, satisfies the projected equation for some $\tau.\,$ So in some sense, the choice of $A$ restricts your choice of $V$; they are not independent of each other.
Another way of looking at it: every column of $(I-B^+B)$ must be a linear combination of the eigenvectors of $V$ associated with a single eigenvalue, $\lambda=2\tau$.
$\tau$ can be calculated by equating the traces.
$$\eqalign{
{\rm tr}(X) &= {\rm tr}(X_s) \\
\tau &= B^+:W^T - \tau B^+:I + (I- B^+B)^T:Y \\
\tau\,(1+I:B^+) &= W^T:B^+ + (I-B^+B):Y \\
\tau &= \frac{W^T:B^+ + (I-B^+B):Y}{1+I:B^+} \\
}$$
Substitute this value into the expression for $X_s\\$
NB: In the above, a colon is used as a convenient product notation for the trace, i.e.
$$A:B = {\rm tr}(A^TB)$$
Properties of the trace allow terms in a colon product to be rearranged in lots of ways.
$$\eqalign{
A:B &= B:A \\
A:B &= A^T:B^T \\
A:BC &= B^TA:C = AC^T:B \\
}$$
A: Presumably the matrices are real. Let $r$ be the rank of $A$. Orthogonally diagonalise $A^TA$ as $Q(D\oplus0)Q^T$, where $D$ is a $r\times r$ positive diagonal matrix. Let also
$$
X^T=Q\pmatrix{X_1&X_2\\ X_3&X_4}Q^T,\quad V=Q\pmatrix{V_1&V_2\\ V_3&V_4}Q^T,
$$
where both $X_1$ and $V_1$ are $r\times r$. The equation can then be rewritten as
$$
2\pmatrix{X_1D&0\\ X_3D&0}=-2\operatorname{tr}(X)I+\pmatrix{V_1&V_2\\ V_3&V_4},
$$
i.e.
$$
\pmatrix{X_1&0\\ X_3&0}=\pmatrix{\frac12\left(-2\operatorname{tr}(X)I_r+V_1\right)D^{-1}&V_2\\ \frac12V_3D^{-1}&-2\operatorname{tr}(X)I_{m-r}+V_4}.
$$
Therefore, it is solvable if and only if $V_2=0$ and $V_4=2tI_{m-r}$ for some number $t$. If this is the case, the general solution is given by
$$
X^T=Q\pmatrix{\frac12\left(-2tI_r+V_1\right)D^{-1}&X_2\\ \frac12V_3D^{-1}&X_4}Q^T
$$
where $X_2$ is arbitrary and $X_4$ is any matrix whose trace is $\alpha=t-\frac12\operatorname{tr}\left(\left(-2tI_r+V_1\right)D^{-1}\right)$ (so that the trace of $X$ is $t$).
If you don't want to use partitioned matrices, you may rewrite the above solution as follows. Let $P=A^TA$. Then the equation is solvable if and only if $V(I-P^+P)=2t(I-P^+P)$ for some $t\in\mathbb R$. If this is the case, the general solution is given by
$$
X^T=\frac12(-2tI+V)P^+ + \left(\alpha I + M - \frac1n\operatorname{tr}(M(I-P^+P))I\right)(I-P^+P)
$$
where $M$ is an arbitrary matrix and
$$
\alpha = t-\frac12\operatorname{tr}\left((-2tI+V)P^+\right).
$$
