The code below demonstrates the following problem:
Analytically, the matrix x is NOT singular [1]. Matlab believes it is singular due to limits on floating point precision. Documentation dictates that using det(x) to determine if a matrix is singular is poor practice, and using rcond(x) (for instance) is better [2]. However, in this case, det(x) yields the analytical solution of the determinant. Why does det(x) accurately determine that x is not singular while rcond(x) does not?
a = -1.3589e-10;b = -1.7108e-9;c = 12.5893;d = -1e11;x = [a b; c d];analytical_determinant = a*d - b*c; %[3]
matlab_determinant = det(x);eigens = eig(x);eigen_determinant = eigens(1)*eigens(2); %[4]
rcond_result = rcond(x);disp('Let''s try to take an inverse:')inv(x);fprintf('rcond result: %f\nanalytical det: %f\ndet(x) result: %f\ndeterminant from eig: %f\n',rcond_result,analytical_determinant,matlab_determinant,eigen_determinant);
Best Answer