Matlab: value non-zero but it should

  • Context: MATLAB 
  • Thread starter Thread starter Rizlablack
  • Start date Start date
  • Tags Tags
    Matlab Value
Click For Summary

Discussion Overview

The discussion revolves around the behavior of the Matlab function det when calculating the determinant of a matrix that is expected to be zero. Participants explore the reasons behind the output of a very small non-zero value instead of the expected zero.

Discussion Character

  • Technical explanation
  • Conceptual clarification
  • Debate/contested

Main Points Raised

  • One participant notes that the determinant of the matrix a=[1,2,3;4,5,6;7,8,9] should be zero, but Matlab returns 6.6613e-16.
  • Another participant suggests that this discrepancy arises because not all decimal numbers can be represented exactly in binary, leading to small errors in computation.
  • A different participant explains that Matlab uses a general-purpose algorithm for calculating determinants, possibly involving LU decomposition, which can introduce inexactness due to scaling tricks used for stability.
  • One participant expresses gratitude for the clarification, indicating that they feel reassured about their understanding of the situation.

Areas of Agreement / Disagreement

Participants do not reach a consensus on a single explanation but present multiple perspectives on the reasons for the non-zero output, indicating that the discussion remains unresolved.

Contextual Notes

The discussion highlights limitations in numerical representation and the implications of algorithmic approaches in computational mathematics, without resolving the specific impact of these factors on the determinant calculation.

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 32 ·
2
Replies
32
Views
4K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 4 ·
Replies
4
Views
8K