let $\mathbf a$ and $\mathbf b$ be 3D vectors. Find a $3\times3$ matrix $\mathbf R$ such that $\mathbf {Ra} = \mathbf a_{\bot \mathbf b}$. Hi as the title says im trying to find this.
let $\mathbf a$ and $\mathbf b$ be 3D vectors. Find a  $3\times3$ matrix $\mathbf R$ such that  $\mathbf {Ra} = \mathbf a_{\bot \mathbf b}$.
according to my exercises the answer is
$$ R = \frac{1}{b^2} 
    \begin{bmatrix}
    b^2_y+b^2_z & -b_xb_y & -b_xb_z \\
    -b_xb_y & b^2_x+b^2_z & -b_yb_z \\
    -b_xb_z & -b_yb_z & b^2_x+b^2_y \\
    \end{bmatrix}
$$
I haven't been able to get to this solution and i've managed to get as far as
$$
 a_{\bot b} = a - a_{||b} = a - \frac{a\cdot b}{b^2}b
$$
and i can substitute $ a_{||b} $ for its expression as a matrix product  $$
 a_{||b} = \frac{1}{b^2}bb^{\mathrm T}a $$
and this is an outer product so it becomes
$$a_{\bot b} = \frac{1}{b^2}\begin{bmatrix}
    b^2_x & b_xb_y & b_xb_z \\
    b_xb_y & b^2_y & b_yb_z \\
    b_xb_z & b_yb_z & b^2_z+b^2_y \\
    \end{bmatrix}\begin{bmatrix}
    a_x  \\
    a_y  \\
    a_z  \\
    \end{bmatrix}$$
from this I can get
$$
Ra = a -  \frac{1}{b^2}\begin{bmatrix}
    b^2_x & b_xb_y & b_xb_z \\
    b_xb_y & b^2_y & b_yb_z \\
    b_xb_z & b_yb_z & b^2_z+b^2_y \\
    \end{bmatrix}\begin{bmatrix}
    a_x  \\
    a_y  \\
    a_z  \\
    \end{bmatrix}
$$
This is as far as i was able to get and im not sure the steps needed to get the last equation to the first.
Thanks for any insight anyone can provide.

The last few steps will be
$$ \begin{align*} Ra &= a - \frac{1}{b^2}\begin{bmatrix}b_x^2 & b_xb_y & b_xb_z\\ b_xb_y & b_y^2 & b_yb_z\\ b_xb_z & b_yb_z & b_z^2\end{bmatrix}a\\ &= \frac{1}{b^2}\Bigg(b^2I -  \begin{bmatrix}b_x^2 & b_xb_y & b_xb_z\\ b_xb_y & b_y^2 & b_yb_z\\ b_xb_z & b_yb_z & b_z^2\end{bmatrix}\Bigg)a \\ \end{align*}$$
Notice that $b^2 = b_x^2 + b_y^2 + b_z^2$. So
$$\begin{align*} Ra &= \frac{1}{b^2}\Bigg(\begin{bmatrix}b_x^2  + b_y^2 + b_z^2& 0 & 0\\ 0 & b_x^2  + b_y^2 + b_z^2 & 0\\ 0 & 0 & b_x^2  + b_y^2 + b_z^2\end{bmatrix}-\begin{bmatrix}b_x^2 & b_xb_y & b_xb_z\\ b_xb_y & b_y^2 & b_yb_z\\ b_xb_z & b_yb_z & b_z^2\end{bmatrix}\Bigg)a \\ &= \frac{1}{b^2}\begin{bmatrix}b_y^2 + b_z^2 & -b_xb_y & -b_xb_z\\ -b_xb_y & b_x^2 + b_z^2 & -b_yb_z\\ -b_xb_z & -b_yb_z & b_x^2 + b_y^2\end{bmatrix}a\end{align*} $$
Hence
$$ R = \frac{1}{b^2}\begin{bmatrix}b_y^2 + b_z^2 & -b_xb_y & -b_xb_z\\ -b_xb_y & b_x^2 + b_z^2 & -b_yb_z\\ -b_xb_z & -b_yb_z & b_x^2 + b_y^2\end{bmatrix}$$
