Let A be an n-by-n matrix with complex entries.
A is said to be diagonalizable if there exist
n-by-n matrices P and D with complex 
entries such that D is a diagonal matrix
and A is equal to P times D times the inverse of P.
There is a simple test for diagonalizability
of a matrix and it's the following:
A is diagonalizable if and only if
for every eigenvalue lambda of A,
the geometric multiplicity of lambda is equal to
the algebraic multiplicity of lambda.
An equivalent way of saying this is that
the sum of the geometric multiplicities
of all the eigenvalues of A
is equal to n. let's take a look at an
example
Let's take a look at an example.
Suppose that my matrix A is 1 2, 0 1.
Now let's form the characteristic polynomial.
So it's the determinant of
1 minus lambda, 2, 0, 1 minus lambda.
And that's just 1 minus lambda, squared.
So lambda equal to 1 is the only eigenvalue.
And it has algebraic multiplicity 2
because it appears as a root of 
this polynomial twice.
What's its geometric multiplicity?
For that, we need to look at the nullspace
of this matrix, which is simply 0 2, 0 0.
But this matrix has rank 1.
So the nullity of A is also 1.
So, lambda has geometric multiplicity 1.
And that's less than 2.
So A is not diagonalizable.
Let's look at another example.
This time we let
A be this matrix and the characteristic
polynomial
is going to be this.  So I'm omitting the
calculations here.
you can check it for yourself.
So the eigenvalues are 4 and 5
And the algebraic multiplicity of 4 is 1.
And the algebraic multiplicity of 5 is 2.
We want to find out the geometric multiplicity
of these eigenvalues.
The geometric multiplicity for 4 is
simply 1 because, by definition, the
geometric multiplicity cannot be 0
and it cannot exceed the algebraic multiplicity
in this case it's 1, so the geometric 
multiplicity must be 1.
But what about 5?
Let's take a look at this matrix.
And we'll try to figure out its nullity.
And we're going to row reduce it
by adding 2 times row 1 to row 2.
And this is what we get.
And then we multiply row 1 by -1
I get down to this matrix which is in
reduced row-echelon form.
Now there's only one pivot.
So the nullity is going to be 3 minus 1,
which is 2.
So we can say from this that
A is diagonalizable.
Now the question is how do we find the matrices
P and D as required by the definition.
So this is what we're going to do next.
The way to do it is, we first find a basis
for the eigenspace for each eigenvalue.
For the eigenspace for the eigenvalue 4,
we need to look at the matrix A - 4 I
and that is 0 0 -2, 2 1 4, and 0 0 1.
And clearly, I can take
the vector -1/2 1 0.
What about the eigenspace for the eigenvalue 5.
Here, we're looking at a basis for the
nullspace of this.
And it doesn't take too long to see that
we can take
0 1 0 and -2 0 1.
So these two vectors give a basis for
the eigenspace for the eigenvalue 5.
Now, once we have these two bases,
we can form D and P as follows:
So for the matrix D,
you just put the eigenvalues on the diagonal
and we include multiple copies as
indicated by the geometric multiplicity.
So here I can put 4 and 5 and 5
because 5 has geometric multiplicity 2.
Now to form P, you have to look at D.
So to form the first column of P,
you look at the first diagonal entry in D,
and find a vector in the basis for the
eigenspace corresponding to the eigenvalue.
And here, the eigenvalue is 4,
and there's only one vector in the basis.
So I put that vector as the first column of P.
Now I look at the second column of P
and want to decide what to put in there.
I look at the second diagonal entry.
The eigenvalue is 5.  So I look at the
basis for the eigenspace for the eigenvalue
5 and pick a vector that
has not appeared in P before.
And I can pick 0 1 0.
I could have picked -2 0 1 as well
but the choice for the column 2 will
affect the choice for column 3.
Column 3 also has 5 as eigenvalue.
And as I mentioned,
you need to go to the basis
for the eigenspace of eigenvalue 5
and find a vector that has appeared in P before.
And this case
has no choice but to choose -2 0 1.
You can check that the inverse of P
is going to be -2 0 -4, 2 1 4, and 0 0 1
And if you carry out the calculations
you'll see that P times D times P inverse
is indeed A.
