MATLAB Matlab: value non-zero but it should

  • Thread starter Thread starter Rizlablack
  • Start date Start date
  • Tags Tags
    Matlab Value
AI Thread Summary
In this discussion, a user new to Matlab encounters an issue when calculating the determinant of a matrix, expecting a result of zero for the matrix a = [1,2,3;4,5,6;7,8,9], but receives 6.6613e-16 instead. The explanation centers around the limitations of numerical representation in computers, particularly how binary systems cannot represent all decimal numbers exactly, leading to small errors in calculations. The conversation highlights that Matlab uses a general-purpose algorithm for computing determinants, likely based on LU decomposition rather than simpler methods like the expansion of minors. This approach, while efficient, introduces scaling techniques that enhance stability but can result in slight inaccuracies, such as the near-zero determinant value observed. The user expresses gratitude for the clarification, confirming their understanding of the issue.
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!
 

Similar threads

Replies
4
Views
2K
Replies
5
Views
3K
Replies
4
Views
2K
Replies
2
Views
1K
Replies
2
Views
2K
Replies
3
Views
2K
Replies
1
Views
2K
Replies
2
Views
1K
Back
Top