<s>[INST] How to find Jordan basis of a matrix Assume matrix 
$$A=
\begin{bmatrix}
-1&0&0&0&0\\
-1&1&-2&0&1\\
-1&0&-1&0&1\\
0&1&-1&1&0\\
0&0&0&0&-1
\end{bmatrix}
$$
Its Jordan Canonical Form is
$$J=
\begin{bmatrix}
-1&1&0&0&0\\
0&-1&0&0&0\\
0&0&-1&0&0\\
0&0&0&1&1\\
0&0&0&0&1
\end{bmatrix}
$$
I am trying to find a nonsingular $P$, let $P=\begin{bmatrix}\mathbf{p}_1&\mathbf{p}_2&\mathbf{p}_3&\mathbf{p}_4&\mathbf{p}_5\end{bmatrix}$ s.t. $J=P^{-1}AP\Leftrightarrow AP=PJ$.
I came up with the Wikipedia article on JCF and I think I need to find the generalized eigenvectors so that
$AP=PJ=\begin{bmatrix}-\mathbf{p_1}&\mathbf{p_1}-\mathbf{p_2}&-\mathbf{p_3}&\mathbf{p_4}&\mathbf{p_4}+\mathbf{p_5}\end{bmatrix}$ yielding the systems
$$(A+I)\mathbf{p_1}=\mathbf{0}$$
$$(A+I)^2\mathbf{p_2}=\mathbf{0}$$
$$(A+I)\mathbf{p_3}=\mathbf{0}$$
$$(A-I)\mathbf{p_4}=\mathbf{0}$$
$$(A-I)^2\mathbf{p_5}=\mathbf{0}$$
I solved each of these systems making sure that the vectors $\mathbf{p_i}$ I chose are linearly independent. So I chose
$$P=\begin{bmatrix}\mathbf{p}_1&\mathbf{p}_2&\mathbf{p}_3&\mathbf{p}_4&\mathbf{p}_5\end{bmatrix}=\begin{bmatrix}1&2&-2&0&0\\1&1&2&0&1\\1&1&2&0&0\\0&0&0&1&1\\1&1&-2&0&0\end{bmatrix}$$
which even though is nonsingular I am not getting $AP=PJ$.
What am I doing wrong?
 [/INST] I got the Jordan blocks in slightly different order.
What you seem to be missing is the consistency part: in my
$$ P = 
\left(
\begin{array}{rrrrr}
1 & 0 & 0 & 0 & 0 \\
0 & 1 & 0 & 0 & 1 \\
0 & 1 & 0 & 0 & 0 \\
0 & 0 & 0 & 1 & 0 \\
1 & 0 & 1 & 0 & 0
\end{array}
\right) 
$$
we have a place where we do have $(A+I)^2 p_3 = 0,$ but we have consistency in that $p_2 =(A+I)p_3 .$ It follows automatically that $(A+I)p_2 = (A+I)^2 p_3 = 0.$
We also have $(A-I)^2 p_5 = 0,$ then $p_4 =(A-I)p_5.$ As a result $(A-I) p_4 = 0.$
$$
\left(
\begin{array}{rrrrr}
1 & 0 & 0 & 0 & 0 \\
0 & 0 & 1 & 0 & 0 \\
-1 & 0 & 0 & 0 & 1 \\
0 & 0 & 0 & 1 & 0 \\
0 & 1 & -1 & 0 & 0
\end{array}
\right)
\left(
\begin{array}{rrrrr}
-1 & 0 & 0 & 0 & 0 \\
-1 & 1 & -2 & 0 & 1 \\
-1 & 0 & -1 & 0 & 1 \\
0 & 1 & -1 & 1 & 0 \\
0 & 0 & 0 & 0 & -1
\end{array}
\right)
\left(
\begin{array}{rrrrr}
1 & 0 & 0 & 0 & 0 \\
0 & 1 & 0 & 0 & 1 \\
0 & 1 & 0 & 0 & 0 \\
0 & 0 & 0 & 1 & 0 \\
1 & 0 & 1 & 0 & 0
\end{array}
\right) =
\left(
\begin{array}{rrrrr}
-1 & 0 & 0 & 0 & 0 \\
0 & -1 & 1 & 0 & 0 \\
0 & 0 & -1 & 0 & 0 \\
0 & 0 & 0 & 1 & 1 \\
0 & 0 & 0 & 0 & 1
\end{array}
\right)
$$
To get the Jordan form in the order they report, use my columns but permuted, $p_2p_3p_1p_4p_5$ and then correct $P^{-1}.$ We can correct $P^{-1}$ by permuting the rows to 23145.
</s>