I consider myself to be an inexperienced Mathematica user so maybe someone could point out what am I doing wrong.

In short, here is what I want to get: suppose that there is a matrix of dimension $ N \times N $. I know that at least one of the eigenvalues should always be zero. What I need to determine is the maximum number of non-zero eigenvalues; no need for explicit ones. I found out that the function MatrixRank should do it. I came across one of the matrices, which seemed to "violate" the rule for eigenvalues, in the sense that I wasn't getting a zero eigenvalue. Later I was pointed out that determinant of the given matrix is "0".

Here comes the issue. 2 functions return different results for a matrix of dimension 3:

Simplify[Det[M]] ->  0 
MatrixRank[M]    ->  3

Due to the specific matrix being way too long, I include a link to it. This is the original matrix, I use TrigToExp afterwards as it seemed to reduce the computation process time. In both cases I got the same result for Det and MatrixRank.

P.S. I need a symbolic evaluation and am currently using Mathematica

  • 3
    $\begingroup$ If one of the eigenvalues are 0, then the determinant is zero, because the determinant equals the product of all eigenvalues... $\endgroup$ Commented Oct 25, 2018 at 12:47
  • 1
    $\begingroup$ When Mathematica calculated the MatrixRank with symbolic entries, it gives the "most general"/"least specific" value of the rank. Maybe that is your issue... $\endgroup$ Commented Oct 25, 2018 at 12:49
  • $\begingroup$ Thank you for comments. I am still interested if it would be possible to determine amount of the non-zero eigenvalues without using numerical evaluation. Or maybe there are some other mathematical possibilities of doing that? In principle, this could be further reduced by hand, but I want a more or less to automate it as there are way more matrices. $\endgroup$
    – Biduin A
    Commented Oct 25, 2018 at 12:57
  • $\begingroup$ Did you try NullSpace? Presumably this gives the dimension of the nullspace, which is the number of zero eigenvalues. $\endgroup$
    – bill s
    Commented Oct 31, 2018 at 16:32
  • $\begingroup$ Are you sure of your Det calculation? I just tried with your 3x3 matrix and the det simplifies, but does not obviously equal zero. Perhaps you mean some specific values of the parameters? If so, please show these values. $\endgroup$
    – bill s
    Commented Oct 31, 2018 at 16:41

1 Answer 1


If a numerical method is acceptable, you can find the characteristic polynomial, and then find out how many coefficients are zero. Let mat be your matrix. Then:

coeff = CoefficientList[CharacteristicPolynomial[mat, x], x];

With[{v = Reduce`FreeVariables @ mat},
    rules = Thread[v -> RandomReal[10, Length @ v, WorkingPrecision->50]]
coeff /. rules

{0.*10^-45 + 0.*10^-45 I, -88.06869475049593825389409426950881792625734818 + 0.*10^-46 I, 41.6148105746435957281515196867572568226297329616, -1.000000000000000000000000000000000000000000000000}

This shows that the matrix rank is at least 2 (only the constant term is zero).

Or, just use Eigenvalues:

Eigenvalues[mat /. rules]
Chop @ %

{39.378334721261585770434684505881112377002680998 - 8.9642095056061798556155811000294566716875029005*10^-58 I, 2.23647585338200995771683518087614444562705196366 + 5.0089274479735025489970467486450317946657226813*10^-58 I, 2.48749661365029255751887504501496855632934665698*10^-60 - 6.4330798253441844711669847353350620993805252084*10^-60 I}

{39.378334721261585770434684505881112377002680998, 2.23647585338200995771683518087614444562705196366, 0}

I think the characteristic polynomial approach is probably a bit more robust, since it avoids root finding.

  • 1
    $\begingroup$ CharacteristicPolynomial with approximate numeric input uses Eigenvalues. $\endgroup$ Commented Oct 31, 2018 at 17:25
  • $\begingroup$ @DanielLichtblau Did not know that. However, my use of CharacteristicPolynomial had exact input, so I don't think your comment is relevant? $\endgroup$
    – Carl Woll
    Commented Oct 31, 2018 at 17:36
  • 1
    $\begingroup$ If mat is exact then CharacteristicPolynomial[mat] will use different methods e.g. polynomial interpolation for integer/rational matrices (and that will be much faster than Eigenvalues). $\endgroup$ Commented Oct 31, 2018 at 19:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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