MATLAB: Problem in calculating a determinant for a matrix

matrix

Hello, I am a doctoral student in automatic control and I use matlab for matrix calculations. I gave matlab the following matrix 16 * 16 and I know that its determinant is zero, and that is not reversible but matlab not given the same expected results.
Example below:
A=[100,200,300,400,500,600,700,800,900,100,200,300,400,500,600,-6600; 100,100,300,400,500,600,700,800,900,100,200,300,400,500,600,-6500; 100,200,100,600,500,600,700,800,900,100,200,300,400,500,600,-6600; 100,100,300,100,500,600,700,800,900,100,200,300,400,500,600,-6200; 100,200,300,400,200,600,900,800,900,100,200,300,400,500,600,-6500; 100,200,300,400,500,100,700,800,900,100,200,300,500,600,700,-6400; 100,300,300,400,500,600,100,800,900,100,200,300,400,500,600,-6100; 100,200,300,400,500,600,700,100,900,100,300,400,400,500,600,-6100; 100,200,300,400,600,600,700,800,200,100,200,300,400,500,600,-6000; 100,200,300,400,500,600,700,800,900,100,200,300,400,600,600,-6700; 100,200,300,400,500,700,700,800,900,200,200,300,400,500,600,-6800; 100,200,300,400,500,600,700,800,900,100,200,100,500,600,600,-6600; 100,200,300,400,500,600,700,800,900,100,200,300,100,700,600,-6500; 100,200,300,400,500,600,700,800,900,100,300,300,400,300,600,-6500; 100,200,300,400,500,600,800,800,900,100,200,400,400,500,200,-6400; 100,200,300,400,500,600,700,800,900,100,200,300,500,500,600,-6700]
Normally for this matrix, the determinant is zero. But Matlab gaves me the determinant equal to -9.024461178341880e+21 What is the problem ? Thank you in advance for your reply.

Best Answer

Nobody bothered to answer this homework question yet? Return to linear algebra 101.
1. If the determinant of the nxn matrix A is D, then the determinant of the matrix k*A is k^n*D.
2. DON'T USE THE DETERMINANT!!!!!!!!!!!!!! EVER!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Because of 1, it is trivial to create a matrix that will result in any garbage answer that you desire, at least in terms of floating point arithmetic. This is exactly what you have discovered, i.e., a matrix that should be singular, yet returns numerical trash from the determinant.
3. The determinant of a matrix can be written as the product of the eigenvalues. (See 1!) It also can be computed as the product of the diagonals of the U factor from an LU factorization. This is what det does.
Look at the diagonals from the LU factor of the matrix that you have created.
[L,U] = lu(A);
diag(U)
ans =
100
-100
-200
-300
-300
-500
-600
-700
-700
100
100
-200
-300
100
-400
1.4211e-14
prod(diag(U))
ans =
-9.0245e+21
See that the matrix is clearly singular. Yet, the one tiny diagonal element, which is numerically zero compared to the rest in terms, is overwhelmed when you form the product.
det(A/100)
ans =
7.0504e-11
Is the matrix singular? OF COURSE IT IS!
rank(A)
ans =
15
4. Use rank to determine the rank of a matrix. If you know a little more about linear algebra, then you can use other tools like cond or svd.
cond(A)
ans =
6.0814e+17
In the end, unless you thoroughly understand det, and know why and when not to use it, you should never use det. And IF you do understand all of this about det, then you should also know why you almost never need to use det!