Using Matlab's det(), why does this 3x3 matrix's determinant not zero?
13 ビュー (過去 30 日間)
古いコメントを表示
x= [1 2 3;4 5 6;7 8 9]; det(x)
ans = 6.6613e-16
That 3x3 matrix is shown in various linear algebra books to give an example of a matrix where the determinant is zero. You can check the calculation from Wolframalpha's page .

However, when I use Matlab (from old versions to 64-bit 2017b) on a 64-bit Windows 10 machine, I always got a non-zero value.
Is this some kind of a bug or is this a problem shown from the "det()" function's calculation method?
I really want to know why Matlab gives a non-zero value.
-Regards, Matthew
2 件のコメント
Geoff Hayes
2018 年 2 月 8 日
Matthew - see http://matlab.wikia.com/wiki/FAQ#Why_is_0.3_-_0.2_-_0.1_.28or_similar.29_not_equal_to_zero.3F for a explanation of why you are getting a very small but non-zero answer.
採用された回答
Steven Lord
2018 年 2 月 8 日
My suspicion is that widget is specialized to work on 3-by-3 matrices. If so I wouldn't be surprised if it uses the explicit formula for the determinant of a 3-by-3 matrix given in the Wikipedia article. Since it uses multiplication on the integer values you specified then adds or subtracts those products, it will return an integer answer.
But as the Calculation section of the Wikipedia states, that gets very inefficient very quickly as the size of the matrix increases. As stated in the documentation, MATLAB uses a matrix decomposition. It is more susceptible to round-off errors (as the Limitation section of the documentation page notes) but its performance scales much better than something like cofactor expansion.
If you're using det to try to determine if the matrix is singular, I wouldn't. You can have a very simple matrix that is non-singular but for which det returns 0 due to underflow, like a scaled identity matrix:
A = 0.1*eye(350); % a non-zero multiple of the identity is not singular
dA = det(A) % underflow
Or you can have a matrix that is very nearly singular but for which det returns a value larger than 0 (in absolute value, not relative to the elements of the matrix.)
B = [1 1; 1 1+eps]; % row 2 is almost the same as row 1
C = 1e10*B;
dB = det(B) % very small, B is nearly singular
dC = det(C) % not so small, but C is just a scaled version of B
Use the cond or rcond to compute the condition number (or the reciprocal condition number, in the case of rcond) instead.
cA = cond(A) % 1, non-singular
cB = cond(B) % large, nearly singular
cC = cond(C) % large, nearly singular
1 件のコメント
その他の回答 (0 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!