Why is det a bad way to check matrix singularity?

30 views (last 30 days)
Sorry, I can't define "bad" in the question. I've heard this several times and I've never liked determinants and I just finished the book Basic Matrices by C.G. Broyden and he didn't use determinants either. So could someone please clarify? Thank you.

Accepted Answer

John D'Errico
John D'Errico on 11 May 2018
The example I always like to give is this:
det(3*eye(1000))
ans =
Inf
det(.3*eye(1000))
ans =
0
det(eye(1000))
ans =
1
So is that very simply scaled identity matrix singular or not?
Or, try this:
A = rand(4,3)*rand(3,4);
det(A)
ans =
-3.79011315068409e-18
So the product of a 4x3 and a 3x4 matrix MUST be singular. Hey, det got that right. By the same logic, the product of a random 100x99 matrix and a 99x100 matrix must also be singular. Right?
A = rand(100,99)*rand(99,100);
det(A)
ans =
2.93629717617442e+37
Not according to det. So what went wrong?
Det uses a good scheme to do its work. It computed a pivoted LU factorization of the matrix. Then take the product of the diagonal elements of U.
[L,U,P] = lu(A);
prod(diag(U))
ans =
2.9363e+37
diag(U)
ans =
32.338
3.298
2.9682
-2.8183
2.8772
2.5713
2.7686
3.7067
-3.5259
4.1328
-6.0407
3.0507
2.7318
3.69
-3.8034
-3.3593
3.507
3.8023
-3.0113
-3.2846
5.2249
-3.0531
-5.1457
-2.868
-3.3524
2.3689
-3.3529
4.1264
7.6471
-3.7107
-4.1193
-3.6732
-4.1213
2.5827
5.6856
2.3059
4.7825
2.9447
5.1117
-3.6831
6.3472
-5.7061
3.2259
-3.5116
-2.7813
-3.812
-7.6134
4.2924
-3.3689
-2.8465
-3.3392
3.5206
3.5484
2.8341
4.7295
-4.1757
-4.8612
3.4009
-3.8609
4.5162
4.7767
6.3942
-3.7804
-3.707
4.0019
-2.2507
-4.4813
2.0913
3.813
4.8703
-3.3253
3.1835
-5.4834
4.0471
-6.381
1.3069
3.4877
-2.0475
3.0452
-2.6165
-2.1811
-4.9662
2.6201
-2.8188
4.2236
-1.5627
3.5806
-2.8705
1.8628
-2.2577
-1.9378
1.5462
-1.0559
-0.64591
-2.391
1.0017
-0.79486
0.43954
-0.069129
-1.2492e-12
But what happened here is that last diagonal element should in theory be mathematically 0. In fact, that last element was a small number, effectively down near eps. Then when you take the product of the elements, that one small number can become overwhelmed by the others.
So while rank and cond are not fooled, det got blown out of the water.
rank(A)
ans =
99
cond(A)
ans =
1.4581e+17
In the end, you can't trust det.
Sadly, this is what I wish those who teach students about using det would also teach them - one last lesson on why you should NOT trust it.

More Answers (2)

Steven Lord
Steven Lord on 11 May 2018
A non-zero scalar multiple of the identity matrix is about as far from singular as you can get, right?
A = 0.1*eye(400);
dA = det(A)
cA = cond(A)
dA is 0 because of underflow, which indicates that A is singular. Large condition numbers indicate a nearly singular matrix, and condition numbers must be greater than or equal to 1, so the fact that cA is 1 indicates that A is far from singular.
B = [1 1; 1 1+eps];
dB = det(B)
cB = cond(B)
In this case, dB is small AND cB is large, which both indicate that B is nearly singular.
C = flintmax*B;
dC = det(C)
cC = cond(C)
In this case, dC is large in absolute value (1.8e16) and cC is the same as cB. The determinant indicates that C is not singular, the condition number indicates that it is. Since it's a non-zero constant multiple of a nearly singular matrix, it too is nearly singular.
In theory, you could determine if a matrix was non-singular using the determinant. In practice, you shouldn't.
My first example is a more extreme version of the example Cleve uses on pages 17-18 of the Linear Equations chapter of his textbook Numerical Computing with MATLAB. You might find the discussion of norms and condition numbers there interesting.
  1 Comment
Bence Meszaros
Bence Meszaros on 12 May 2018
Thank you for your explanation and for the link to the book. I'll check the book for sure.

Sign in to comment.


dpb
dpb on 11 May 2018
You can start with <Limitations of det> for bare bones; I don't have link at hand but a search will probably uncover it; I'm almost positive I recall Cleve having discoursed on the subject in the past in one of his enlightening amplifications on various matrix algebra topics...

Categories

Find more on Linear Algebra in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!