Let $x, y\in\mathbb{R}^n$. I would like to rotate $y$ so that it is perpendicular to $x$. Is it possible to find a matrix $R\in\mathbb{R}^{n\times n}$ that does that?
$$ x^\top Ry = 0 $$
Attempt
The matrix must be orthogonal $RR^\top =I$. This means we must have $$ \sum_{k=1}^n r_{ik} r_{jk} = \delta_{ij} \qquad \forall i,j\in\{1, \ldots, n\} $$ Since $RR^\top$ is symmetric, we must have that the above and below diagonal entries are the same, thus they would lead to the same constraints. Overall we have $n$ diagonal and $\frac{1}{2}n(n-1)$ off-diagonal constraints for a total of $\frac{1}{2}n(n+1)$ constraints. In addition, we also have the constraints given by the condition that $y'=Ry$ is perpendicular to $x$ $$ \sum_{i=1}^n\sum_{j=1}^n x_i R_{ij} y_j = 0 $$ Thus we have $\frac{1}{2}n^2 + \frac{1}{2}n + 1$ constraints. One final constrain, in order for $R$ to be a proper rotation, is given by the determinant $\det(R) = 1$, which gives one more constraint. Overall we have $$ \frac{1}{2}n^2 + \frac{1}{2}n + 2 $$ constraints. However, $R$ has $n^2$ entries.
First, find the orthogonal projection of $y$ onto the line spanned by $x$ - call it $\hat y$. This amounts to saying $\hat y=u(y\cdot u)$, where $u=x/\|x\|$, the unit vector for that line. The matrix for this is
$$P=\begin{bmatrix}u_1^2&u_1u_2&u_1u_3&\cdots\\u_2u_1&u_2^2&u_2u_3&\cdots\\u_3u_1&u_3u_2&u_3^2&\cdots\\\vdots&\vdots&\vdots&\cdots\end{bmatrix}$$
Such that $\hat y=Py$. Now, the projection onto the orthogonal complement of this is $I-P$. $I$ denotes the identity matrix. From now on, $\hat y$ refers to the orthogonal projection of $y$ onto the orthogonal complement of the line spanned by $x$. This will orthogonally project $y$ onto a line orthogonal to $x$, but we need a rotation of $y$ - we must make it the same length. So we need to rescale by $\|y\|/\|\hat y\|$. The length of this new orthogonal projection, $\hat y=(I-P)y$, is calculated as follows:
$$\|(I-P)y\|=\|y-Py\|=\|y-u(y\cdot u)\|$$
I don’t know how to make a single matrix to accomplish this, but very simply we can say $x^T(I-P)y=0$, and to make this a proper rotation we scale $(I-P)y$ by $\|y\|/\|(I-P)y\|$.
Concrete example:
$$x=\begin{pmatrix}2\\4\\5\end{pmatrix},\,y=\begin{pmatrix}2\\1\\2\end{pmatrix},\|x\|=3\sqrt{5},\,\|y\|=3\\u=\begin{pmatrix}\frac{2}{3\sqrt{5}}\\\frac{4}{3\sqrt{5}}\\\frac{\sqrt{5}}{3}\end{pmatrix}\\P=\frac{1}{45}\begin{pmatrix}4&8&10\\8&16&20\\10&20&25\end{pmatrix}\\I-P=\frac{1}{45}\begin{pmatrix}41&-8&-10\\-8&29&-20\\-10&-20&20\end{pmatrix}\\\hat y=(I-P)y=\frac{1}{45}\begin{pmatrix}54\\-27\\0\end{pmatrix}=\begin{pmatrix}\frac{6}{5}\\-\frac{3}{5}\\0\end{pmatrix}$$
And $\hat y$ is orthogonal to $x$, but is not the same length as $y$, so the rescale is necessary.