How to find a positive semidefinite matrix $Y$ such that $YB =0$ where $B$ is given $B$ is an $n\times m$ matrix, $m\leq n$.
I have to find an $n\times n$ positive semidefinite matrix $Y$ such that $YB = 0$. 
Please help me figure out how can I find the matrix $Y$.
 A: If $X$ is any (real) matrix with the property that $XB=0$, then $Y=X^TX$ will do the trick. Such a matrix $Y$ is always positive semidefinite. To see this note that for any (column) vector $v$ we have $v^TYv=(Xv)^T(Xv)=|Xv|^2\ge0$. 
How to find such a matrix $X$? If $m=n$ and $\det B\neq0$, then there is no other choice but $Y=0$. Otherwise we can do the following. The rows of $X$ should be orthogonal to the columns of $B$. Let $v=(v_1,v_2,\ldots,v_n)$ be a vector of unknowns. From our assumptions it follows that the homogeneous linear system $B^Tv=0$ has non-trivial solutions: either $m<n$ or there are linear dependencies among the equations as $B$ has rank $<n$. Let $U$ be the set of solutions (use whatever methods you know to find a basis for $U$). Then any matrix $X$ with row vectors that (or rather their transposes) are from the space $U$ will work.
A: I can give you the answer in the case $m=n$. 


*

*if $\det(B)\neq 0$ then $B$ is invertible, and therefore the only matrix $Y$ is $Y=0$.

*if $\det(B)=0$ then take $Y=adj(B)$, where $adj(B)$ is the adjugate matrix of $B$.
Oops... I forgot about the fact that $Y$ must be positive semidefinite. Sorry.
A: Use Singular Value Decomposition! Note $YB=0$ implies each row of $Y$ is in the left null space of matrix $B$. SVD is a good tool to find the left or right null space of a given matrix.
Let $r$ be the rank of matrix $B$. Then an SVD of $B$ is like
$$B=U\Sigma V^T$$
where $U=(u_1,...,u_{r-1},u_r,...,u_n)\in\mathbb{R}^{n\times n}$ and $V\in\mathbb{R}^{m\times m}$ are orthogonal matrices.
It is easy to check $u_i^TB=0$ for $i=r+1,...,n$. Choose $U_1=(u_{r+1},...,u_n)^T\in\mathbb{R}^{n-r\times n}$, then $U_1B=0$. Choose $Y=U_1^TU_1\in\mathbb{R}^{n\times n}$, then $Y$ is a positive semidefinite matrix with rank as $n-r$ and $YB=0$.
