Finding the Jordan Canonical Form of a Matrix

Let's begin with a matrix A.


  Clear[JA];
  A={{1,1,-1},{0,0,2},{0,-1,3}};
  MatrixForm[A]

We will put A in Jordan form. Do do this we need to find a nonsingular matrix S such that Inv(S)AS=J, where J is the Jordan form. This matrix S will be made up of eigenvectors and "generalized eigenvectors" as we shall see.

First, we must find the eigenvalues of A.


  Eigenvalues[A]

You notice that A has a repeated eigenvalue. This does not necessarily mean that A does not have a full complement of eigenvectors. Let's see.


  
  Eigenvectors[A]

Notice that by listing an eigenvector of {0,0,0}, Mathematica is
telling you that A does not have a full complement of eigenvectors. We must search for "generalized eigenvectors".

An eigenvector v solves the matrix equation Av=lambda v
[or (A-lambda I)v=0, where I is the identity matrix]. A generalized eigenvector v(i) will solve the matrix equation

Av(i)=lambda(i) v(i) + v(i-1)

[note that v(i) represents a subscript].
Here v(i) is the generalized eigenvector corresponding to the eigenvector v(i-1)
This equation can be written (A-lambda(i) I)v(i)=v(i-1).

v(1)=the first eigenvector, v(2)=generalized eigenvector to go with v(1), and v(3) is the second eigenvector. A generalized eigenvector will go in each slot that Mathematica gives the zero vector as an eigenvector.


  LinearSolve[A-1 IdentityMatrix[3],{1,0,0}]

We have just found v(2), the generalized eigenvector to go with v(1)={1,0,0}. We now have three vectors to form the nonsingular matrix S. Inv(S)AS should give us the Jordan form of A.


  S=Transpose[{{1,0,0},{0,2,1},{0,1,1}}];
  MatrixForm[S]


  JA=Inverse[S].A.S;
  MatrixForm[JA]

Let's try another one.


  Clear[B,S]


  B={{2,-1,2,0},{0,3,-1,0},{0,1,1,0},{0,1,-3,5}};
  MatrixForm[B]


  Eigenvalues[B]

You notice that B has a repeated eigenvalue. This does not necessarily mean that B does not have a full complement of eigenvectors. Let's see.


  Eigenvectors[B]

Notice that by listing an eigenvector of {0,0,0,0} twice, Mathematica is
telling you that B does not have a full complement of eigenvectors. We must search for 2 "generalized eigenvectors".


  LinearSolve[B-2 IdentityMatrix[4],{1,0,0,0}]

Let's keep going....


  LinearSolve[B-2 IdentityMatrix[4],{0,1,1,2/3}]

We now have our four vectors for the matrix S.


  S=Transpose[{{1,0,0,0},{0,1,1,2/3},{0,2,1,5/9},{0,0,0,1}}];
  MatrixForm[S]


  JB=Inverse[S].B.S;
  MatrixForm[JB]

Up to Jordan Canonical Form