Let $S^n$ be the space of symmetric $n\times n$ matrices, and let $L \subset S^n$ be a rational affine subspace. By vectorization we may describe this subspace in the form $A q = b$ for some matrix $A$ with $n(n+1)/2$ columns. Given a real matrix $Q\in S^n$, this method finds a nearby rational matrix $Q_p$ on $L$.
The object roundPSDmatrix is a function closure.