Finding $\bf{P}$ such that $\bf{P^{-1}AP=B}$ for both fixed $\bf{A}，\bf{B}$. How can I  find a matrix $\bf{P}\in \mathbb{{R}^{n\times n}}$, such that $\bf{P^{-1}AP=B}$，where
$$\bf{A}=\begin{bmatrix}
 \bf{A_2}&  \bf{C_2}&    \\ 
 &  \bf{A_2}&  \bf{C_2}&  \\ 
 &  &  \ddots&  \ddots&   \\ 
 &  &   &  \bf{A_2}&\bf{C_2} \\ 
 & & & &\bf{A_2}
\end{bmatrix},$$
$$\bf{B}=\begin{bmatrix}
 \bf{B_2}&  \bf{C_2}&    \\ 
 &  \bf{B_2}&  \bf{C_2}&  \\ 
 &  &  \ddots&  \ddots&   \\ 
 &  &   &  \bf{B_2}&\bf{C_2}\\ 
 & & & &\bf{B_2}
\end{bmatrix}.$$
$$\bf{C_2}=\begin{bmatrix}
 0& 0\\ 
 1& 0
\end{bmatrix}，\bf{B_2}=\begin{bmatrix}
 a& -b\\ 
 b& a
\end{bmatrix}$$ and$$
 \bf{A_2}=\begin{bmatrix}
 0& 1\\ 
 -(a^2+b^2)& 2a
\end{bmatrix}.\quad \textit{a}\in\mathbb{R}, \textit{b}\left(\ne \textrm{0}\right)\in\mathbb{R}.$$

Let $\bf{P_2}=\begin{bmatrix}
 0& 1\\ 
 b& a
\end{bmatrix}\left(\bf{P_2}^{-1}=\begin{bmatrix}
 -a/b& 1/b\\ 
 1& 0
\end{bmatrix}\right)$ ，we have $\bf{P_2}^{-1}\bf{A_2}\bf{P_2}=\bf{B_2}$.
But$$\bf{P^{-1}AP\ne B},
\textrm{we set }\bf{P}=\begin{bmatrix}
 \bf{P_2}&  &    \\ 
 &  \bf{P_2}&  &\\ 
 &   & &\ddots&   \\ 
 &  &   &  &\bf{P_2} \\ 
 \end{bmatrix}.$$ In fact, $\bf{P_2}^{-1}\bf{C_2}\bf{P_2}\ne\bf{C_2}.$ So the above $\bf{P}$ is  undesirable,we need  some other ways to find $\bf{P}$ satisfying the  requirement. 
 A: Let $X=\pmatrix{1&0\\ a&-b}$. Since $b\ne0$, $X$ is non-singular. Then
\begin{aligned}
A_2X
&=\pmatrix{0&1\\ -(a^2+b^2)&2a}\pmatrix{1&0\\ a&-b}\\
&=\pmatrix{a&-b\\ a^2-b^2&-2ab}=\pmatrix{1&0\\ a&-b}\pmatrix{a&-b\\ b&a}=XB_2,\\
-bC_2X
&=-\pmatrix{0&0\\ b&0}\pmatrix{1&0\\ a&-b}\\
&=\pmatrix{0&0\\ -b&0}
=\pmatrix{1&0\\ a&-b}\pmatrix{0&0\\ 1&0}=XC_2.
\end{aligned}
It follows that if $n=2m$,
\begin{aligned}
&\phantom{=}\pmatrix{
A_2&C_2\\ 
&A_2&C_2\\ 
&&\ddots&\ddots\\ 
&&&A_2&C_2 \\ 
&&&&A_2}
\pmatrix{X\\ &-bX\\ &&b^2X\\ &&&\ddots\\ &&&&(-b)^{m-1}X}\\
&=\pmatrix{
A_2X&-bC_2X\\ 
&-bA_2X&b^2C_2X\\ 
&&\ddots&\ddots\\ 
&&&(-b)^{m-2}A_2X&(-b)^{m-1}C_2X\\ 
&&&&(-b)^{m-1}A_2X}\\
&=\pmatrix{
XB_2&XC_2\\ 
&-bXB_2&-bXC_2\\ 
&&\ddots&\ddots\\ 
&&&(-b)^{m-2}XB_2&(-b)^{m-2}XC_2\\ 
&&&&(-b)^{m-1}XB_2}\\
&=\pmatrix{X\\ &-bX\\ &&b^2X\\ &&&\ddots\\ &&&&(-b)^{m-1}X}
\pmatrix{
B_2&C_2\\ 
&B_2&C_2\\ 
&&\ddots&\ddots\\ 
&&&B_2&C_2 \\ 
&&&&B_2}.
\end{aligned}
Hence you may take $P=\operatorname{diag}\left(X,\,-bX,\,b^2X,\,\ldots,\,(-b)^{m-1}X\right)$.

How $P$ was found. One natural way to solve the problem is to find $P_1$ and $P_2$ that make both $P_1^{-1}AP_1$ and $P_2^{-1}BP_2$ equal to their common Jordan form. Then one may set $P=P_1P_2^{-1}$. But I was too lazy to do that. So, I tried to play around with $A$ and $B$ to see if there were any shortcut.

The first thing I noticed was that if $AP=PB$, we must also have $f(A)P=Pf(B)$. If we take $f$ to be the common characteristic polynomial of $A_2$ and $B_2$, i.e. if we take $f(x)=x^2-2ax+(a^2+b^2)$, then
$$
f(A)=J=\pmatrix{0&I_2\\ &\ddots&\ddots\\ &&\ddots&I_2\\ &&&0}
$$
and $f(B)=-bJ$. The equation $f(A)P=Pf(B)$ thus becomes $JP=-bPJ$, which forces $P$ to take the folloiwng form:
$$
\pmatrix{X&Y&Z&\cdots&\cdots&\vdots\\ &-bX&-bY&-bZ&\cdots&\vdots\\ &&b^2X&b^2Y&\ddots&\vdots\\ &&&\ddots&\ddots\\ &&&&(-b)^{m-2}X&(-b)^{m-2}Y\\ &&&&&(-b)^{m-1}X}.
$$
The equation $AP=PB$ now reduces to a system of equations
\begin{aligned}
A_2X-XB_2&=0,\\
A_2Y-YB_2&=XC_2+bC_2X,\\
A_2Z-ZB_2&=YC_2+bC_2Y,\\
&\vdots
\end{aligned}
and the obvious thing to try is to set $Y=Z=\cdots=0$ and solve $A_2X-XB_2=0=XC_2+bC_2X$. Now the rest is easy.
A: You find $Q$ such that $Q^{-1}AQ=\Lambda$ is in Jordan form, and you find $R$ such that $R^{-1}BR=\Lambda$ (if there is no $R$, that is, if $A,B$ don't have the same Jordan form, then $P$ doesn't exist), and then you have $RQ^{-1}AQR^{-1}=B$, so $P=QR^{-1}$. 
