Description
The goal of this assignment is write an algorithm that can check if a matrix is
diagonalizable over the real numbers, and if so, give an orthonormal basis of eigenvectors for the image of a square matrix.
Complete the following steps:
Step 1. Calculate the characteristic polynomial of A by using >>p = poly(A)
(the polynomial is a vector, with the first number being the coefficient
of the largest power and the last number is the constant term).
Step 2. Find the roots of p by calling >>v = roots(p), then sort the roots by using
>>sort(v) (For all my examples the eigenvalues will be integers, you may
want to use Matlab’s round function to make the values nice).
Step 3. For each different eigenvalue λ, find the corresponding eigenspace Eλ. (You
should use matlab’s unique function on v, this is so that you only do this
for each different number in V.
To do this, calculate the null space of A−λ∗I by using Matlab’s null(B)
function.
Step 4. For each eigenvalue λ check if the dimension of Eλ is the algebraic multiplicity of λ ( how many times λ appears in v). If these two values are not equal
for an eigenvalue, throw an error saying ”The matrix is not diagonalizable.”.
Step 5. For each eigenvalue λ use your function grams.m from lab 8 to find an orthonormal basis of the eigenspace Eλ, these will be eigenvectors for λ.
Step 6. Let P be a matrix the same size as A, let the columns of P be all the
orthonormal eigenvectors from all passes of step 5. Make sure to group the
columns of P so that left most columns are in the eigenspace of the smallest
eigenvalue, and so on (the order within each block of eigenvectors with the
same eigenvalue does not matter).
Step 7. Let D be a matrix the same size as A, let D have all zeros on the off diagonal and the diagonal should be v. >>D = diag(v) works.
Step 8. P is in fact orthonormal since eigenvectors of different eigenvalues are perpendicular. So check that P is orthonormal by checking that P
T P = I the
identity matrix. Hence P
−1 = P
T
. Lastly check that A = P DP T
.
Thus, we have D = P
−1AP, a diagonalization of A. Notice then that AP = P D,
so for a column pi of P, Api = D(i, i)pi where D(i, i) is the eigenvalue for pi
; this
is the definition of an eigenvalue-eigenvector pair.
1
2
Example: Let A =
1 2
2 4
, then the eigenvalues are 0, 5 and E5 = span 1
2
and E0 = span −2
1
(Matlab might give you not nice numbers if you call
null(A − 5I), but it will be a scalar multiple of span 1
2
). So one choice for P
is P =
−2/
√
5 1/
√
5
1/
√
5 2/
√
5
.
Check your function on the 3 matrices given in the .txt file on blackboard in your
diary.
Submit a .m file for your function and a .txt file for your diary.

