Quadratic matrix equation $X^TBX=A$ Let $A$ and $B$ be two positive semidefinite $n \times n$ matrices. Does the following matrix quadratic equation have a solution?
$$X^TBX=A$$
When $B$ is positive definite the solution is 
$$X=B^{-1/2}QA^{1/2}$$
where $Q$ is an orthogonal matrix.
 A: We assume that the matrices are real. Note that $A^{1/2},B^{1/2}$ are well defined.
Let $Y=B^{1/2}X$. Then $Y^TY=A$ and $Y=QA^{1/2}$ where $Q$ is arbitrary in $O(n)$. Finally, we consider the linear equation  $(*)$ $B^{1/2}X=QA^{1/2}$.
We use, in the sequel the Moore-Penrose inverse $(.)^{+}$, cf.
https://en.wikipedia.org/wiki/Moore%E2%80%93Penrose_inverse
EDIT.  $(*)$ has some solution iff 
$(**)$ $B^{1/2}{B^{1/2}}^+QA^{1/2}=QA^{1/2}$. 
Note that the condition $(**)$ depends on $Q$ and, consequently, gives the admissible matrices $Q$. When $(**)$ is satisfied for a fixed $Q$ (that implies in particular that $rank(B)\geq rank(A)$ as user1551 wrote), then the general solution of $(*)$ (for this choice of $Q$) is
$X={B^{1/2}}^+QA^{1/2}+(I-{B^{1/2}}^+B^{1/2})W$ where $W$ is an arbitrary $n\times n$ matrix.
Note that if $B=Udiag(\lambda_1,\cdots,\lambda_r,0_{n-r})U^T$ where $\lambda_i>0, r=rank(B)$ and $U\in O(n)$, then ${B^{1/2}}^+=Udiag(1/\sqrt{\lambda_1},\cdots,1/\sqrt{\lambda_r},0_{n-r})U^T$. In particular, $B^{1/2},{B^{1/2}}^+$ commute.
As a consequence of the previous note, it is easy to see that 
$\textbf{Remark 1}$. The above solutions satisfy $X^TBX=A$.
$\textbf{Remark 2}$. $(**)$ is equivalent to $Q(im(A))\subset im(B)$.
