2
$\begingroup$

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?

$\endgroup$
3
$\begingroup$

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|>

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

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.)

$\endgroup$

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.