Let's have two quadrics (as input): $Q_1$ and $Q_2$. These are symmetric 4x4 matrices of reals.
I want to find a transformation (9 degrees of liberty: 3 for rotation, 3 for scale and 3 for translation) such that:
\begin{equation} \DeclareMathOperator*{\argmin}{argmin} T^* = \argmin_{T \in \mathbb{R}^{4 \times 4}} \| T^\top Q_1 T - Q_2 \|_F^2 \end{equation}
That is, applying a rigid transformation to the first quadric to align it with the second. So far, I decomposed this problem like this:
\begin{align} E &= \| T^\top Q_1 T - Q_2 \|_F^2 \\ &= \text{tr}((T^\top Q_1 T - Q_2)(T^\top Q_1 T - Q_2)^\top) \\ &= \text{tr}(T^\top Q_1 T T^\top Q_1 T) - 2\,\text{tr}(T^\top Q_1 T Q_2) + \text{tr}(Q_2^2) \\ \\ \frac{\partial E}{\partial T} &= 4Q_1 T (T^\top Q_1 T - Q_2) \\ \\ \frac{\partial E}{\partial T} = 0 &\Leftrightarrow Q_1 T (T^\top Q_1 T - Q_2) = 0 \end{align}
That gives me 16 polynomial equations for 9 unknowns, but if I try to write it I get an astronomically long expression (and Maple just hang on it).
How can I solve it ?