1function c = cheap_condest (d, fail_if_singular) 2%CHEAP_CONDEST checks the diagonal of a triangular matrix 3 4% Copyright 2011-2012, Timothy A. Davis, http://www.suitesparse.com 5 6if (isempty (d)) 7 dmin = 1 ; 8 dmax = 1 ; 9else 10 d = abs (d) ; 11 dmin = min (d) ; 12 dmax = max (d) ; 13end 14if (dmin == 0) 15 if (fail_if_singular) 16 error ('MATLAB:singularMatrix', ... 17 'Matrix is singular to working precision.'); 18 else 19 warning ('MATLAB:singularMatrix', ... 20 'Matrix is singular to working precision.'); 21 end 22elseif (dmin < 2 * eps * (dmax)) 23 % MATLAB treats this as a warning, but it is treated here as an error 24 % so that F=factorize(A) will abandon this factorization and use a 25 % better one, in its default strategy. 26 if (fail_if_singular) 27 error ('MATLAB:nearlySingularMatrix', ... 28 ['Matrix is close to singular or badly scaled.\n' ... 29 ' Results may be inaccurate. RCOND = %g'], dmin / dmax) ; 30 else 31 warning ('MATLAB:nearlySingularMatrix', ... 32 ['Matrix is close to singular or badly scaled.\n' ... 33 ' Results may be inaccurate. RCOND = %g'], dmin / dmax) ; 34 end 35end 36if (dmin == 0) 37 c = inf ; 38else 39 c = dmax / dmin ; 40end 41 42