Matlab: value non-zero but it should

  • Context: MATLAB 
  • Thread starter Thread starter Rizlablack
  • Start date Start date
  • Tags Tags
    Matlab Value
Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
3 replies · 3K views
Rizlablack
Messages
8
Reaction score
0
Hello everybody!
I'm quite new with Matlab and I'm starting trying some stuff..
well I was trying to input

det(a)

where a=[1,2,3;4,5,6;7,8,9] and this should be zero. And I mean 0.0000
but the result is

6.6613e-16

why?O.o
 
Physics news on Phys.org
I think it is because not all 10-base numbers can be represented exactly in the computer. You see, the computer works in binary and it has a finite number of bits to represent number, in other words, there is a given resolution between the two closest numbers that the computer can represent...so, when you get a number that cannot be represented exactly, it is going to be given the closest value the machine can represent...so, little by little, you start having an error.
 
Matlab doesn't have a special-purpose determinant algorithm for 2x2 matrices, another for 3x3 matrices, another for 4x4 matrices, etc. It instead uses a general purpose algorithm that works for any NxN matrix.

Which algorithm?

I can't find Matlab implementation of det, but it definitely is not expansion of minors. That's an O(n!) algorithm. It probably uses some matrix decomposition, most likely LU decomposition:
  • Decompose the matrix as a product of a lower diagonal and upper diagonal matrix (LU decomposition).
  • Compute the product of the diagonals of the decomposed matrices.
  • Negate this product if an odd number of pivots were made in the LU decomposition.

Any decent matrix decomposition algorithm will use various scaling tricks to make the algorithm stable. While this scaling does make the algorithm stable, it also makes your exact numbers inexact. Hence the 6.6e-16 value for the determinant (which is essentially zero).
 
thank you very much D H.. I had some clues that could be something like that but now I'm quite sure I'm not doing anything wrong!