Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Matlab: value non-zero but it should

  1. Oct 27, 2012 #1
    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
     
  2. jcsd
  3. Oct 27, 2012 #2
    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.
     
  4. Oct 27, 2012 #3

    D H

    User Avatar
    Staff Emeritus
    Science Advisor

    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).
     
  5. Oct 27, 2012 #4
    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!
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: Matlab: value non-zero but it should
Loading...