Rotation matrix in order to rotate orthogonal vectors onto x-axis, y-axis, etc... Assume that I have a set of $n$ orthogonal vectors in $n$-dimensional space such that they span the whole space.  These vectors are of arbitrary length and are not necessarily unit vectors.  
How do I construct a rotation matrix that will rotate the vectors onto the x-axis, y-axis, z-axis, etc... while preserving their original length?
I intend to use this matrix to rotate an entire space.  
 A: Let $v_1,\dots,v_n$ be your $n$ vectors. Recalling that the columns of a transformation matrix are images of basis vectors, the matrix that maps the standard basis to these vectors is $$\begin{bmatrix}v_1&\cdots&v_n\end{bmatrix}.$$ Since we want to preserve lengths, we normalize each of the $v_k$ before assembling them into this matrix. The matrix that maps the $v_k$ onto the coordinate axes is then the inverse of this matrix, but because we’ve assumed that the $v_k$ are orthogonal, its inverse is simply its transpose, so the matrix that we’re looking for is $$R=\begin{bmatrix}{v_1^T\over\|v_1\|} \\ \vdots \\ {v_n^T\over\|v_n\|}\end{bmatrix},$$ i.e., the $k$th row of the desired transformation matrix is $v_k$ normalized. Note, however, that although $R$ is an orthogonal matrix, for it to be a rotation we must also have $\det R=1$, which means that $(v_1,\dots,v_n)$ must form a right-handed basis for $\mathbb R^n$.
A: Let $\mathbf{v}_1, \ldots, \mathbf{v}_n$ be the set of orthogonal vectors. 
Let $d_1, \ldots, d_n$ be the lengths of the vectors (all $d_i \ne 0$).
Let $\hat{\mathbf{u}}_1, \ldots, \hat{\mathbf{u}}_n$ be the unit vectors obtained from the original set of vectors after dividing by each of the $d_i$'s.
Let $U$ be the matrix formed by taking the $\hat{\mathbf{u}}_i$'s as its columns. $U$ is an orthogonal matrix i.e. $U U^T = I$.
Going from the standard basis $\hat{\mathbf{e}}_1, \ldots, \hat{\mathbf{e}}_n$ to the original set, we need to scale each $\hat{\mathbf{e}}_i$ by $d_i$ first then multiply by $U$.
The scaling can be achieved by multiplying by a diagonal matrix $D$ which has $D_{ii} = d_i$ and $D_{ij} = 0$ for $i \ne j$.
So transforming from the standard basis to the set of $\mathbf{v}_i$'s is achieved by multiplying by $D$ then $U$ i.e. by the matrix $M = U D$.
Going the other way is achieved by multiplying by $M^{-1} = D^{-1} U^{-1}= D^{-1} U^{T}$.  The matrix $D^{-1}$ is also diagonal and has its $i^{th}$ diagonal entry as $1/ d_{i}$.
If one wants to map the vectors to the standard basis without changing the length then applying $U^T$ is sufficient.
