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?

  • 1
    $\begingroup$ Why not start with the eigenvalues to build the matrices? If you write down the characteristic equation, you can deduce what the matrix might look like $\endgroup$
    – Shuri2060
    Jul 11 '17 at 21:16
  • 1
    $\begingroup$ I think you mean "distinct" as opposed to "unique" $\endgroup$
    – Will Jagy
    Jul 11 '17 at 21:22
  • 1
    $\begingroup$ If there are no constraints on the matrices generate a diagonal matrix, with integer values and conjugate it by orthogonal matrices. $\endgroup$ Jul 11 '17 at 21:24
  • 1
    $\begingroup$ No need to use orthogonal matrices to conjugate it by, you can use any nonsingular matrices. $\endgroup$ Jul 11 '17 at 21:26

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.

  • 1
    $\begingroup$ 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. math.stackexchange.com/questions/803313/… $\endgroup$
    – Widawensen
    Jul 12 '17 at 10:32
  • $\begingroup$ @Widawensen, yes, absolutely. Thanks (also on behalf of the OP:) ! $\endgroup$
    – avs
    Jul 12 '17 at 16:58
  • $\begingroup$ @avs, only problem is when the inverse of A has floats :/ have an idea for how I could control that? $\endgroup$
    – maddie
    Jul 13 '17 at 0:57
  • 1
    $\begingroup$ @avs, I guess I could just repeat step 2 until the determinant of A is +/- 1 math.stackexchange.com/questions/19528/… $\endgroup$
    – maddie
    Jul 13 '17 at 1:02
  • 1
    $\begingroup$ @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$ $\endgroup$
    – Widawensen
    Jul 13 '17 at 16:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.