23 views (last 30 days)

A=[1,4,7;11,5,-1;0,2,4]

det(A)

= -3.3509e-15

which is wrong and the result is actually equal to 0.

why does matlab calculate it wrong?

Samuele Sandrini
on 22 Mar 2020

To calculate the determinant Matlab doesn't use an analytical formula but to calculate it in a simpler way, first it passes from the LU factorization which is susceptible to floating-point round-off errors (Limitations and Algorithms of function det).

Note:

The LU factorization allows to write the matrix A as the product of two matrices (L, U) where L is lower triangular and U is upper triangular.

Therefore:

in this way it is easier calculate the determinant because L and U are triangular.

Alternative:

If you want to verify that the matrix A is singular you can use the condition number (cond) and if it assumes very high values it means that the matrix is "close" to the singularity.

Otherwise, if you need to invert the matrix A you can use the operator "\" which uses more efficient methods (you could reading about it in this answer) .

Sign in to comment.

Sign in to answer this question.

Opportunities for recent engineering grads.

Apply Today
## 6 Comments

## Direct link to this comment

https://fr.mathworks.com/matlabcentral/answers/512289-matlab-gives-wrong-answer-to-determinant-of-a-3x3-matrix#comment_813637

⋮## Direct link to this comment

https://fr.mathworks.com/matlabcentral/answers/512289-matlab-gives-wrong-answer-to-determinant-of-a-3x3-matrix#comment_813637

## Direct link to this comment

https://fr.mathworks.com/matlabcentral/answers/512289-matlab-gives-wrong-answer-to-determinant-of-a-3x3-matrix#comment_813640

⋮## Direct link to this comment

https://fr.mathworks.com/matlabcentral/answers/512289-matlab-gives-wrong-answer-to-determinant-of-a-3x3-matrix#comment_813640

## Direct link to this comment

https://fr.mathworks.com/matlabcentral/answers/512289-matlab-gives-wrong-answer-to-determinant-of-a-3x3-matrix#comment_813650

⋮## Direct link to this comment

https://fr.mathworks.com/matlabcentral/answers/512289-matlab-gives-wrong-answer-to-determinant-of-a-3x3-matrix#comment_813650

## Direct link to this comment

https://fr.mathworks.com/matlabcentral/answers/512289-matlab-gives-wrong-answer-to-determinant-of-a-3x3-matrix#comment_813668

⋮## Direct link to this comment

https://fr.mathworks.com/matlabcentral/answers/512289-matlab-gives-wrong-answer-to-determinant-of-a-3x3-matrix#comment_813668

## Direct link to this comment

https://fr.mathworks.com/matlabcentral/answers/512289-matlab-gives-wrong-answer-to-determinant-of-a-3x3-matrix#comment_813690

⋮## Direct link to this comment

https://fr.mathworks.com/matlabcentral/answers/512289-matlab-gives-wrong-answer-to-determinant-of-a-3x3-matrix#comment_813690

## Direct link to this comment

https://fr.mathworks.com/matlabcentral/answers/512289-matlab-gives-wrong-answer-to-determinant-of-a-3x3-matrix#comment_813820

⋮## Direct link to this comment

https://fr.mathworks.com/matlabcentral/answers/512289-matlab-gives-wrong-answer-to-determinant-of-a-3x3-matrix#comment_813820

Sign in to comment.