You are on page 1of 3

221 MATLAB ASSIGNMENT 5

DUE 14 NOVEMBER 2019

This assignment comes with a file Ex5Data.mat. Import this file as you did in Exercise 1—refer to Exercise 1 if
you can’t remember how.
This assignment concerns eigenvalues and eigenvectors of a square matrix.

D ETERMINANTS
If A is a square matrix, then
>> det(A)
will calculate the determinant of A.

E IGENVECTORS
The code
>> e = eig(A)
stores in e a column vector containing the eigenvalues of square matrix A. If λ is a root of the characteristic poly-
nomial multiple times, it will appear more than once in this vector.
The code
>> [V,D] = eig(A)
stores in D a diagonal matrix of eigenvalues and in V a matrix whose columns are corresponding eigenvectors.
Another useful command is
>> null(A)
which produces a basis for the null space of a matrix A. You may prefer to use
>> null(A, ’r’)
which does not scale the basis vectors to have length 1, and therefore gives more pleasant answers.

Determinants and Eigenvalues. If A is an n × n matrix, then let p A (x) denote the characteristic polynomial of A.
We can factor p A (x) as
p A (x) = det(A − x I n ) = (−1)n (x − λ1 )(x − λ2 ) . . . (x − λn )
where the λi are the eigenvalues of A. The sign (−1)n in the front is +1 if n is even and −1 if n is odd. Note that
there are n eigenvalues here, and it is possible that some eigenvalues appear more than once, i.e., they appear with
algebraic multiplicity.
We can interpret p a (0) in two different ways. First
p A (0) = det(A − 0I n ) = det A.
and second
p A (0) is the constant term of (−1)n (x − λ1 )(x − λ2 ) . . . (x − λn )
which is to say
p A (0) = (−1)n (−1 )(−λ2 ) . . . (−λn ) = (−1)n (−1)n λ1 λ2 . . . λn = λ1 λ2 . . . λn .
We have proved: If A is an n × n matrix, then det(A) is equal to the product of all eigenvalues of A, counted with
multiplicities.
For example, there is a matrix P in the data file. Determine its eigenvalues by
>> eig(P)
The answer should be a list of integers. Then calculate
>> det(P)
and note that it is a product of the integers you found previously.
1
2 DUE 14 NOVEMBER 2019

Possibly helpful reminder. Remember that


>> K=eyes(6)
makes K equal to I 6 . Then you can change individual entries of K by, for example,
>> K(1,3)=7
which changes the 1, 3-entry of K to 7.

Exercise 1.
(a) There is a matrix M in the file. Calculate the eigenvalues of M, and store them in a vector OneAvec.
(b) The largest eigenvector of M is 9. Calculate the dimension of the associated eigenspace and store it in OneBnum.
(c) Calculate the difference between the product of the eigenvalues (with multiplicity) of M and det(M). The MAT-
LAB command prod that calculates the product of the terms in a vector may be useful here. Store the answer
(i.e., product − determinant) in OneCnum. Is it what you expected (you do not have to store anything for this
part of the question)?
The reason that the two quantities, which are theoretically the same, might be different in calculations is
that MATLAB makes rounding errors. In particular, these errors appear in calculations of eigenvalues of M.
One way of avoiding these errors is to force MATLAB to use symbolic calculations (i.e., with fractions and
square-roots) rather than numerical (i.e., with decimals) by declaring that your matrix has symbolic entries.
For instance, you can try repeating the calculation in this question with the matrix:
>> Msymbolic = sym(M)
(d) There is a 6×6 (symbolic) matrix N in the file. Calculate the eigenvalues of N. There are two repeated eigenvalues
of this matrix. For either of these eigenvalues (the answer is the same in each case), calculate the dimension of
the associated eigenspace and store the answer in OneDnum.
(e) How many elements are in the largest linearly independent set {v 1 , . . . , v d } consisting of eigenvectors of N. Store
the answer in OneEnum.
(f ) Make a matrix E 1,1 (2) that is the same as the I 6 except the 1, 1-position, where it is 2. Store it in OneFmat.
(g) Compare E 1,1 (2)N with N . Consider the following conjecture: If λ is an eigenvalue of a matrix Q 0 , and if Q 1 is
obtained from Q 0 by multiplying one row by a scalar c, then the number cλ is an eigenvalue of Q 1 . Is this true?
Store either ‘true’ or ‘false’ in OneGword.

S IMULTANEOUS E IGENVECTORS
A mathematically hard problem is the following: given two n × n matrices A and B , determine whether there is
some vector ~v that is an eigenvector for both A and B at the same time. In this section we show you how to solve
this problem in certain cases.
Suppose ~v is an eigenvector for A with eigenvalue c and also an eigenvector for B with eigenvalue d . Then
v = A(B~
(AB )~ v ) = A(d~
v ) = d (A~
v ) = d c~
v
and by the same kind of calculation
(B A)~
v = cd~
v.
Putting these together, we see that
(AB − B A)~
v = AB~
v − B A~
v = d c~
v − cd~
v = (d c − cd )~
v = 0~
v = 0.
This shows that if ~
v is an eigenvector of A and B , then ~
v is in the null space of AB − B A.

Exercise 2.
(a) There are matrices B1 and B2 in the file. Is there a vector that is an eigenvector for both B1 and B2? If there is,
store such a vector in TwoAvec, otherwise store the 0-vector zeros(4,1) in TwoAvec.
(b) There are matrices D1 and D2 in the file. Is there a vector that is an eigenvector for both D1 and D2? If there is,
store such a vector in TwoBvec, otherwise store the 0-vector zeros(4,1) in TwoBvec.
221 MATLAB ASSIGNMENT 5 3

H ANDING IN
It is now time to turn in your second MATLAB assignment for this course. Again you will be handing in your
assignment as a .mat file—that is a matlab file containing all your variables.
Here’s how:
(1) Check that you have a value stored for each of the questions you were asked this week. Your Workspace
should contain: OneAvec, OneBnum, OneCnum, OneDnum, OneEnum,OneFmat,OneGword, TwoAvec, TwoBvec.
Please be aware that these names are case-sensitive. It is ok if your Workspace contains other variables as
well, we will ignore them.
(2) Save all your variables as a .mat file—do not make a .m file by mistake. There are several ways of doing
this, depending on how you are running MATLAB.
• If you’re using matlab.mathworks.com, you should save your variables using the command
>> save Math221Assignment5
This will save the variables in a file called “Math221Assignment5.mat” in mathworks’ cloud storage.
Then you will have to download it to the computer by selecting the file and using the download button:
• If you are running MATLAB on a computer locally, this is done by clicking the “Save workspace” but-
ton near the top of the screen.

(3) Upload your .mat file to Canvas. This is done by going to the Math 221 Canvas site, going to the Assign-
ments page, and following the instructions there.

You might also like