You are on page 1of 6

Eigenvectors and Eigenvalues in MATLAB

Objectives
1. To learn how to compute eigenvalues and eigenvectors using MATLAB's builtin functions.
2. To investigate properties of eigenvalues, eigenvectors.
Prerequisites
1. Fundamentals of matrices and their properties, including determinants, rowreduction, and solving systems of equations.
2. Basic concepts for eigenvalues and eigenvectors and diagonalization.
Background
For A, an nxn matrix, the real number is called an eigenvalue of A if there
exists a nonzero vector x in Rn such that Ax = x. The vector x is called an
eigenvector belonging to . The equation Ax = x is equivalent to (A- I)x = 0, so
all of the following are equivalent:
1. is an eigenvalue of A.
2. (A- I)x = 0 has a nontrivial solution.
3. A- I is singular.
4. det(A- I) = 0.

The eigenvectors for are the nonzero solutions x to (A- I)x=0. These vectors
together with the 0 vector is called the eigenspace corresponding to eigenvalue .
The expression det(A- I) is a polynomial in
of degree n, called the
characteristic polynomial. By property 4, the eigenvalues are the roots of the
characteristic equation det(A- I) = 0.
Determining eigenvalues and eigenvectors with MATLAB:
In MATLAB we can find the characteristic polynomial of a matrix A by entering
poly(A). If A is an nxn matrix, poly(A) is a row vector with n+1 elements that
are the coefficients of the characteristic polynomial. The command roots(C)
computes the roots of the polynomial whose coefficients are the elements of the
vector C. Thus, roots(poly(A)) returns the eigenvalues of A in a column vector.
To find the eigenvectors corresponding to each eigenvalue found above, we
need to find the nonzero solutions x to (A- I)x = 0. One way of doing this in
MATLAB is to compute rref(A- I) and then use Gauss-Jordan elimination as in
Sections 2.2 and 5.3 to find the general solution. (Eigenvectors corresponding to
a particular eigenvalue are not unique.)

Below is a sample session in MATLAB for finding eigenvalues and corresponding


eigenvectors of the matrix
3
A

3
1

A = [3 2 -2; -3 -1 3; 1 2 0]
A=
3
-3
1

2
1
2

2
3
0

Enter matrix A.

2 -2
-1 3
2 0

roots(poly(A))

Compute the roots of characteristic equation


det(A- I)=0; returns eigenvalues 2, 1, and -1.

ans =
2.0000
1.0000
-1.0000
rref(A-2 eye(3))
ans =
1 0
0 1
0 0

0
-1
0

rref(A-1 eye(3))
ans =
1 0
0 1
0 0

Use rref to find the solutions to (A-1I)x = 0


-- the eigenvectors corresponding to = 1.

-1
0
0

rref(A-(-1) eye(3))
ans =
1 0
0 1
0 0

Use rref to find the solutions to (A-2I)x = 0


-- the eigenvectors corresponding to = 2.

Use rref to find the solutions to (A-(-1)I)x = 0


-- the eigenvectors corresponding to = -1.

-1
1
0

The reduced echelon form for A-2I gives the general solution to (A-2I)x=0 as
0
0
x
r
r 1 , the form for eigenvectors corresponding to = 2.
r
1

Similarly, the reduced echelon forms for A-1I


1
eigenvectors of the form s 0 for = 1, and t
1

and A-(-1)I allow us to determine


1
1 corresponding to = -1.
1

A second method of determining the eigenvalues and eigenvectors in MATLAB is


to use the eig function. For an nxn matrix A, eig(A) returns a nx1 column vector
whose elements are the eigenvalues of A. The command in the form
[V D] = eig(A)
computes both the eigenvalues and eigenvectors of A. V will be a matrix whose
columns are eigenvectors of A and D will be a diagonal matrix whose entries
along the diagonal are eigenvalues of A. The ith column of V, V(:,i), is the
eigenvector corresponding to the eigenvalue D(i,i). A sample session is shown
for the matrix A above.
.

eig(A)

Compute the eigenvalues for A.


Note same answer as with roots(poly(A)).

ans =
-1.0000
1.0000
2.0000
[V D] = eig(A)
V=
-0.5774 0.7071 0.0000
0.5774 0.0000 0.7071
-0.5774 0.7071 0.7071

D=
-1.0000
0
0
0 1.0000
0
0
0 2.0000

This form gives us both the eigenvectors in V


and the eigenvalues in D.
The columns of V are the eigenvectors with
norm 1.

Column 1 of V is the eigenvector corresponding


to eigenvalue D(1,1) = -1; column 2 of V is for
D(2,2) = 1; and column 3 of V is for D(3,3) = 2.

From the above we get the same result as before. Note that the eigenvectors
returned in the columns of V are normalized to have length 1 (i.e., norm of each
column is 1), and the general eigenvectors are scalar multiples of these.

For = - 1, r

.5774
.5774 or equivalently r
.5774

1
1 (since r is any real number 0) ;
1

.7071
1
For = 1, s
0 or equivalently s 0
.7071
1
0
0
For = 2, t .7071 or equivalently t 1
.7071
1

Note: In these calculations using MATLAB (or any numerical software


computation package), some round-off error may be introduced. That is why, for
example, the eigenvalues in D are reported as decimal answers.

Diagonalization of Matrices. A square matrix is said to be diagonalizable if


there exists a matrix C such that C-1AC is a diagonal matrix. An important
theorem in linear algebra states that if A is an nxn matrix, then A is diagonalizable
if and only if it has n linearly independent eigenvectors. The matrix C consisting
of the n linearly independent eigenvectors can be used for the similarity
transformation C-1AC to give the diagonal matrix D, which will then consist of
the eigenvalues of A along its diagonal.
In MATLAB we can determine if A is diagonalizable and the similarity
transformation to accomplish the diagonalization by using [V D] = eig(A).
If rank(V) is n, then the n columns of V (which are the eigenvectors) are
linearly independent, the matrix A is diagonalizable, and the diagonalization is
D = V-1AV.

Laboratory on Computing Eigenvalues and Eigenvectors


1. a) Verify ( by using MATLAB to show that ( A- I)x= 0 ) that the following
vectors x, y, and z are eigenvectors for the given eigenvalues of matrix A.
6. 5
A

6
1. 5

7
9
3

10.5

18

7.5

12 for
3

-3

= -1; y = 0 and z = - 1 for


1

=3

b) Choose any random scalars a, b, and c and verify that ax is an eigenvector for
= -1; and that by, cz, and by + cz are all eigenvectors for = 3 (using A, x,
y, and z from part a). Write down the property of eigenvectors and
eigenvalues that is demonstrated.

2. Compute the eigenvalues and corresponding eigenvectors for the following


matrices using the method first discussed in the Background Section (use
roots(poly(A)) to find the eigenvalues and then use the rref(A- I) to compute the
corresponding eigenvectors (general form) for each eigenvalue.
Eigenvalues and corresponding eigenvectors:
a) A

b) A

c) A

5 4
1 2

1 0

2 5

2 4

30

26

14

14

14

10

3. For each of the matrices in exercise 2, use the command [V D] = eig(A) to


determine the eigenvalues and eigenvectors, verifying that you get the same
answer. Also use rank(V) to determine whether the matrix A is diagonalizable.
If it is diagonalizable, verify that D = V-1AV.
a)

rank(V) ________
b)

rank(V) ________
c)

rank(V) ________

If diagonalizable, V-1AV

Diagonalizable? (Yes, No)


D

If diagonalizable, V-1AV

Diagonalizable? (Yes, No)


D

Diagonalizable? (Yes, No)

If diagonalizable, V-1AV

You might also like