1
$\begingroup$

I would like to practice the algorithm for the transformation from a matrix to its jordan normal form (with change of basis).

To do so, I wrote this script that generates random $n \times n$ matrices, with $n \in \{2,3,4,5\}$

import random, numpy  n = random.randint(2,5)  matrix = []  for i in xrange(n):     line = []     for j in xrange(n):         line.append(random.randint(-10, 10))     matrix.append(line)  A = numpy.matrix(matrix)  print("Here is your %i x %i Matrix" % (n, n)) print(A) 

This way of generating random matrices isn't very good for the following reasons:

  • The numbers can get really ugly (example)
  • Sometimes it is not possible to calculate the decomposition of the matrix (example)

Do you know either pages with many examples of "good" matrices up to $5 \times 5$ or do you know how to change my script?

  • 0
    I don't know how you'd do it in numpy, but one approach would be to build up a matrix with known Jordan block structure and then perform a similarity transformation with an orthogonal or unimodular matrix.2012-08-08

1 Answers 1

4

You could generate a Jordan normal form $J$ randomly, then an invertible matrix $X$ randomly and have the algorithm compute $Y=XJX^{-1}$ for you. $Y$ would be your exercise.

  • 0
    This has the added advantage that you know the right answer - it generates problems and an answer sheet. The disadvantage is that $Y$ might not be an integer matrix, even if $X$ and $J$ are.2012-08-08
  • 0
    If you manage to ensure $X$ is integral and its inverse is integral, then your $Y$ will be integral as well.2012-08-08
  • 0
    Sure, but generating such an $X$ randomly seems non-trivial.2012-08-08
  • 0
    @ThomasAndrews I'm not sure how one is supposed to respond to such speculation, but I'll just say the comment was a statement of fact directed at the OP, and not a comment direct at your comment, as you seem to have interpreted it. I'll direct a counterspeculation at your comment though and say that generating an invertible unimodular matrix sounds like something that would be really well-documented online.2012-08-08
  • 0
    He is looking for a practical way to hack together some examples, not advanced algorithmic way of selecting unimodular matrices. (It might suffice to take $X$ to be a random upper-triangular matrix with $1$s along the diagonal to give him a diverse enough example set, for example.)2012-08-08
  • 0
    @ThomasAndrews If it's not speculation you can write "is" instead of "seems", then. As for practicality, if there is a python code out there that generates such matrices, there is nothing more practical than cut-and-paste.2012-08-08
  • 0
    Thanks for your answer rschwieb. I've created this script: https://gist.github.com/32839522012-08-08