Similarity transformation between two state-space (SS) models of the same system I have two minimal discrete time SS models of the same system: $(A_1,B_1,C_1,D_1)$ and $(A_2,B_2,C_2,D_2)$, where $D_1 = D_2$.
I need to find the similarity transformation that exists between the two. I have tried the following method: 
Given $T_2 A_2 T_2^{-1} = \Lambda$ and $T_1 A_1 T_1^{-1} = \Lambda$
I get $(T_1^{-1} T_2) A_2 (T_2^{-1} T_1) = A_1$, and the transformation would be $(T_1^{-1} T_2)$.
This transformation works fine between the $A$ pairs, but wont work between the $B$ and $C$ pairs. I thought for minimal system this would be the case, but that's not true. Can someone suggest a way to find the transformation that I seek please?
 A: So you want to find a $T$ such that
$$
A_1 = T\,A_2\,T^{-1}, \quad B_1 = T\,B_2, \quad C_1 = C_2\,T^{-1}
$$
or equivalently
$$
A_1\,T = T\,A_2, \quad B_1 = T\,B_2, \quad C_1\,T = C_2.
$$
These equations can also be combined into one using the Kronecker product $\otimes$ and vectorization
$$
\underbrace{
\begin{bmatrix}
I \otimes A_1 - A_2^\top \otimes I \\
B_2^\top \otimes I \\
I \otimes C_1
\end{bmatrix}}_M
\mathrm{vec}\, T = 
\underbrace{
\begin{bmatrix}
0 \\
\mathrm{vec}\, B_1 \\
\mathrm{vec}\, C_2
\end{bmatrix}}_v
$$
which can be solved using a pseudo inverse (or directly in MATLAB using M\v)
$$
\mathrm{vec}\, T = \left(M^\top\,M\right)^{-1}M^\top\,v.
$$
This will give the least squares solution of that equation, since there will always be more equations then unknowns. The matrix $T$ can then be reconstructed by simply reshaping the vectorized solution into a square matrix.

It can also be noted that it is also possible to solve for $T$ using either the controllability or observability matrix, which for a general state space model $(A,B,C,D)$ are defined as
$$
\mathcal{C} =
\begin{bmatrix}
B & A\,B & \cdots & A^{n-1}B
\end{bmatrix}
$$
and
$$
\mathcal{O} =
\begin{bmatrix}
C \\ C\,A \\ \vdots \\ C\,A^{n-1}
\end{bmatrix}
$$
respectively, with $n$ such that $A \in \mathbb{R}^{n \times n}$. By substituting in the relation between the two state space models then it can be shown that
$$
\underbrace{
\begin{bmatrix}
B_1 & A_1\,B_1 & \cdots & A_1^{n-1}B_1
\end{bmatrix}}_{\mathcal{C}_1} = T\,
\underbrace{
\begin{bmatrix}
B_2 & A_2\,B_2 & \cdots & A_2^{n-1}B_2
\end{bmatrix}}_{\mathcal{C}_2}
$$
and
$$
\underbrace{
\begin{bmatrix}
C_1 \\ C_1\,A_1 \\ \vdots \\ C_1\,A_1^{n-1}
\end{bmatrix}}_{\mathcal{O}_1}\,T = 
\underbrace{
\begin{bmatrix}
C_2 \\ C_2\,A_2 \\ \vdots \\ C_2\,A_2^{n-1}
\end{bmatrix}}_{\mathcal{O}_2}
$$
This could be solved for $T$ by using one of the following two expressions
$$
\begin{align}
T &= \mathcal{C}_1\,\mathcal{C}_2^{-1} \\
&= \mathcal{O}_1^{-1}\,\mathcal{O}_2
\end{align}
$$
where the inverse might have to be replaced by a pseudo inverse when dealing with a MIMO system. However either of these two methods would fail if either the system is uncontrollable or unobservable. When this is the case you could also combine both the information from the controllability matrices and the observability matrices by again using the Kronecker product and vectorization
$$
\begin{bmatrix}
\mathcal{C}_2^\top \otimes I \\
I \otimes \mathcal{O}_1
\end{bmatrix}
\mathrm{vec}\, T = 
\begin{bmatrix}
\mathrm{vec}\, \mathcal{C}_1 \\
\mathrm{vec}\, \mathcal{O}_2
\end{bmatrix}
$$
which can be solved in a similar way as the first method. Upon numerical testing in MATLAB it does seem that my first method does seem to be both more accurate and faster. You might be able to do something clever when calculating the controllability and observability matrices and stop adding terms with higher powers of $A$ when they are full rank especially when dealing with big MIMO systems.
