0

I am trying to write a program to generate 500 distinct matrices. I'd like to figure out a way to generate matrices with whole eigenvalues.

Currently, I'm using rand to compute the values of my matrix. However, this approach does not make for integer eigenvalues. Instead, the matrices' eigenvalues are all complex floats.

Is there a different approach I could use to build matrices that have whole eigenvalues?

maddie
  • 441

1 Answers1

1

Approach 1, works if the size of the matrix is $\geq 6$. Step 1. Generate a diagonal matrix $\geq 6$ with all eigenvalues distinct. Step 2. Pick 500 distinct permutations on the rows of that matrix. (There are a total 6! = 720 permutations, so you are guaranteed to have 500 distinct ones.)

If the size of the matrix is smaller (say, 4), repeat steps 1-2 above for two or more different sets of 4 distinct eigenvalues.

Approach 2 (less cheap, but more versatile and also generates more interesting matrices):

Do two similar matrices count as distinct? [https://en.wikipedia.org/wiki/Matrix_similarity] If so, you can proceed as follows:

  1. Generate a diagonal matrix $D$ with the desired (integer) eigenvalues.
  2. Generate an invertible matrix $A$ of the same size as $D$.
  3. Record the matrix $A^{-1} D A$.

Repeat steps 1-3 or (if you want to keep the same eigenvalues) just the steps 2-3, making sure no two $A$'s repeat.

avs
  • 6,410
  • 1
    To extend your answer we can use also upper triangular matrices with eigenvalues on the main diagonal. For six eigenvalues we have additional $5 \times 6$ degrees of freedom which can be chosen in absolutely free way. These matrices can be also transformed further by similarity. https://math.stackexchange.com/questions/803313/how-does-this-prove-all-the-eigenvalues-of-a-triangular-matrix-all-of-its-dia – Widawensen Jul 12 '17 at 10:32
  • @Widawensen, yes, absolutely. Thanks (also on behalf of the OP:) ! – avs Jul 12 '17 at 16:58
  • @avs, only problem is when the inverse of A has floats :/ have an idea for how I could control that? – maddie Jul 13 '17 at 00:57
  • 1
    @avs, I guess I could just repeat step 2 until the determinant of A is +/- 1 https://math.stackexchange.com/questions/19528/integer-matrices-with-inverse-integer-matrix – maddie Jul 13 '17 at 01:02
  • 1
    @avs To say truth in the example given by me I forget $ 5 \times 6$ to divide by 2 so the free entries in an upper triangular matrix of dimension $n$ are $n(n-1)/2$ – Widawensen Jul 13 '17 at 16:13
  • @Matt, regardless of what $A^{1-}$ has, the matrix $A^{-1} D A$ has the same eigenvalues as does $D$. – avs Jul 13 '17 at 20:28