# Det, MatrixRank and Eigenvalues

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

• If one of the eigenvalues are 0, then the determinant is zero, because the determinant equals the product of all eigenvalues... – Marius Ladegård Meyer Oct 25 '18 at 12:47
• When Mathematica calculated the MatrixRank with symbolic entries, it gives the "most general"/"least specific" value of the rank. Maybe that is your issue... – Marius Ladegård Meyer Oct 25 '18 at 12:49
• 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. – Biduin A Oct 25 '18 at 12:57
• Did you try NullSpace? Presumably this gives the dimension of the nullspace, which is the number of zero eigenvalues. – bill s Oct 31 '18 at 16:32
• 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. – bill s Oct 31 '18 at 16:41

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

SeedRandom;
With[{v = ReduceFreeVariables @ 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.

• CharacteristicPolynomial with approximate numeric input uses Eigenvalues. – Daniel Lichtblau Oct 31 '18 at 17:25
• @DanielLichtblau Did not know that. However, my use of CharacteristicPolynomial had exact input, so I don't think your comment is relevant? – Carl Woll Oct 31 '18 at 17:36
• 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`). – Daniel Lichtblau Oct 31 '18 at 19:59