# How to return multiplicity of each eigenvalue?

I could not find the information so maybe someone know if it possible.

I have a matrix which has several degenerated eigenvalues and I would like Mathematica to return the multiplicity of each eigenvalue.

Is there any function doing this?

You can use Tally:

ev = Eigenvalues[{{2, 1, 0, 0}, {0, 2, 0, 0}, {0, 0, 1, 0}, {0, 0, 0, 1}}]


{2, 2, 1, 1}

Tally @ ev


{{2, 2}, {1, 2}}

Alternatively, Counts:

Counts @ ev


<|2 -> 2, 1 -> 2|>

• That is exactly what I was looking for, thank you ! – Kawette Oct 4 '18 at 8:03
• @Kawette, my pleasure. Welcome to mma.se. – kglr Oct 4 '18 at 8:04

In exact arithmetic or symbolics, talking about eigenvalue multiplicity is fine. When inexact arithmetic is involved, things are a bit murkier.

As an example of something to be careful about, consider this modified example due to Forsythe:

mat = {{1, 0, -2^(-52)}, {1, 1, 0}, {0, 1, 1}};


Then,

Eigenvalues[mat] // N
{1. + 5.24418*10^-6 I, 1. - 5.24418*10^-6 I, 0.999994}


but,

Eigenvalues[N[mat]]
{1., 1., 1.}


Depending on your application, you might or might not consider the matrix to be nearly degenerate.

(Note that 2^(-52) == \$MachineEpsilon.)