Finding the rotation matrix $R$ in a product $A = R B R^{-1}$, knowing $A$ and $B$ I came across this problem from questions of classical mechanics and rotation of rigid bodies. 
Given a diagonal matrix A (principal moments of inertia of a rigid object in a local reference frame) and an orthonomal matrix R (matrix to rotate the object's reference frame onto a general reference), I can derive a symmetric matrix B (moments of inertia in the general reference frame) though the relationship
$  B = R A R^{-1} $
Playing around with this, I can easily derive A from B, knowing R. The question that puzzled me is: could I also obtain the rotation matrix R if I know A and B? If so, which formulas would allow me to do so? Would I perhaps need additional information and which?
 A: Since $A$ is similar to $B$ due to the relation $B=RAR^{-1}$ for an invertible matrix $R$ (we don't even need orthogonality), we know that these matrices will have the same eigenvalues. But the eigenvalues of a diagonal matrix are just its diagonal entries (since $Ae_1=a_{1,1}e_1$ if $e_1$ is the first basis vector in the reference frame you're in). So, to get $R$ you will need to solve, column by column, for the eigenvectors $v_i$ of $B$ by calculating a non-zero vector that fulfils $(B-a_{i,i}\mathrm{\mathop{Id}})v_i=0$ (here, $\mathrm{\mathop{Id}}$ denotes the identity matrix of the same size as $B$).
When you've done that for all $i$, you will have ended up with the columns of your matrix, except $v_i$ still needs to be re-scaled. So the columns of your matrix $R_{-i}$ are equal to $\frac{v_i}{\|v_i\|}$:
$$R=\left(\frac{v_1}{\|v_1\|},\dotsc,\frac{v_d}{\|v_d\|}\right).$$
EDIT: If you want a proper rotation, you'll want to have $\det(R)=1$, but all we know is that $\det(R)=\pm1$. So, if you calculate your eigenvectors and the determinant ends up being negative, simply switch the sign of one of the columns $R_{-i}$.
A: If $A$ is diagonal, then $BR = RA$ shows that the columns of $R$ are eigenvectors of $B$ corresponding to $[A]_{kk}$. All that remains is scaling.
