MATLAB Answers

# Integer eigenvalues in Matlab

17 views (last 30 days)
Iam Zain on 15 Oct 2021
Commented: Walter Roberson on 15 Oct 2021
I am trying to write a Matlab program which decides if a given (integer) matrix A has integer eigenvalues and if this is the case calculates the eigenvalues and their multiplicities. Any ideas how to get started?
##### 0 CommentsShowHide -1 older comments

Sign in to comment.

### Answers (3)

Bjorn Gustavsson on 15 Oct 2021
Since you have a matrix and want the eigenvalues then the best approach seems to be to actually calculate the eigenvalues. For that use the eig function, see the corresponding help and documentation. For simple extraction of the eigenvalues on the diagonal of the eigenvalue-matrix if you also ask for the eigenvector-matrix have a look at the help and documentation of diag. Then you simply have to check if any of the returned eigenvalues are integers.
HTH
##### 1 CommentShowHide None
Walter Roberson on 15 Oct 2021
The requirement seems to be to evaluate whether it could have integer eigenvalues first, and only calculate the actual eigenvalues if it turns out that they are possible.

Sign in to comment.

Walter Roberson on 15 Oct 2021
Take the symbolic determinant of (matrix minus lambda) . Ask to factor() that. Look for the entries of the form (lambda +/- integer)
If you are not permitted to factor the polynomial directly, then do a long division by lambda - x, which would give you a sequence of terms. But every one of the terms must be integer, so you might be able to start using the Euclid algorithm or a relative of it to try to construct integers that the terms could hold for (waving hands vaguely here.)
##### 0 CommentsShowHide -1 older comments

Sign in to comment.

Paul on 15 Oct 2021
Asusming that "a given (integer) matrix A" means that you know the values of the elements of A, then you can just use eig on the symbolic form of the matrix:
M = sym([ 8, -1; 6, 3]);
e = eig(M)
e =
isAlways(in(e,'integer')) % check in case it's not obvious from the solution.
ans = 2×1 logical array
1 1
M =sym([148544940, 4981764, -15351401, -3212785;
1508678, 105952055, 20746052, 8186704;
616678, -35314190, 162859163, 9445151;
5802184, 13354270, -16966896, 130282468]);
e=eig(M)
e =
isAlways(in(e,'integer'))
ans = 4×1 logical array
1 1 1 1
I'm not sure that is "writing a program." If not, you could use it to compare to what you do write. I don't know how big symbolic M can get before eig() starts having trouble. i tested a 7 x 7 and it was no problem.
##### 0 CommentsShowHide -1 older comments

Sign in to comment.

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!