Anybody working in MATLAB environment? det([1 2; 3 6]) should be a clear ZERO but MATLAB is giving a non-ZERO value for it and this is happening with many more such matrices! Can someone suggest what may be reason.
Hi Minati Mishra , In fact this is one of the limitation of this MATLAB function. check in product help, "det " section limitation, its written that:"The determinant calculation is sometimes numerically unstable. For example, det can produce a large-magnitude determinant for a singular matrix, even though it should have a magnitude of 0."
Minati Mishra - long story short, it is because numerical representation of real numbers.
Using Matlab 2021b, I have obtained the following results:
>> det([1 2; 3 6])
ans =
-3.3307e-16
Using the following command
>> doubleeps = eps('double')
doubleeps =
2.2204e-16
returns a measure of how close numbers can be in double-precision. Therefore, -3.3307e-16 is a rather accurate numerical representation of zero using the double precision. If you want to learn more on computer number formats, you can start reading Wiki at: https://en.wikipedia.org/wiki/Double-precision_floating-point_format
If you really need the return of det([1 2; 3 6]) to be zero (e.g. for if/else conditions), consider using the round function.
Dear Minati, Yes det([1 2; 3 6])=0, but due to the numerical representation of real numbers the result is different. The numerical result you obtained while using MATLAB is near to zero i.e., det([1 2; 3 6])=-3.3307e-16. you can use the round function to get the desired results i.e., round(det([1 2; 3 6])) then the result will be equal to zero. This is how MATLAB works.