Extracting Matrices from the Output of eigenvectors()

In class I sometimes need to use matrices of eigenvalues and eigenvectors, but the output of eigenvectors() isn’t particularly helpful for that out of the box.

Here are two one-liners that work in the case of simple eigenvalues.  I’ll post updates as needed:

First eigU(), takes the output of eigenvectors() and returns matrix of eigenvectors:


And eigdiag(), which takes the output of eigenvectors() and returns diagonal matrix of eigenvalues:



For a matrix with a full set of eigenvectors but eigenvalues of multiplicity greater than one, the lines above fail.  A version of the above that works correctly in that case could look like:



5 thoughts on “Extracting Matrices from the Output of eigenvectors()”

  1. Hi,
    Thanks for the post describing how to use Maxima’s eigenvector and value functions. Unfortunately, there’s still a subtlety in Maxima’s output format that causes the macros you gave above to fail – that is, when Maxima returns vectors that have multiplicities greater than 1.

    For example, consider the matrix:
    M : matrix (
    [1, kb, 0, 0],
    [ka, 1, 0, 0],
    [0, kb * (1 – kb), 1, 0],
    [ka * (1 – ka), 0, 0, 1]

    Maxima returns three eigenvalues for this matrix and lists the last as having two multiplicities. This breaks your macro.

    Do you have any alternate versions that support multiplicities?



    1. Right!

      For a matrix like you describe, I think you could use the lines below
      I know they look awful and don’t really fit the description of “quick one-liner”




      These aren’t entirely general either—
      This fails in the event that maxima can’t find the eigenvectors, as with

      and also fails in the case of a jordan block where there isn’t a full set of eigenvectors


  2. Found this while working with STACK for Moodle, can confirm that your code works there as well. Thank you very much, I was looking for something like this to create online excercises on diagonalization of (symmetric) matrices.


Leave a Reply to Markus Cancel reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: