function X = invert(A) % Usage: X = invert(A) %---------------------------------------------------------------------% % Calculating the inverse of a matrix A % % % % input % % A: a matrix to be inverted % % % % output % % X: the inverse of A, empty if A is numerically singular % % recondA: an estimate of the reciprocal of the condition of A for % % the linear system A*x = b, returned by decomp. % % If rcondA + 1.0 = 1.0, A is singular to the working precision % % % % dependency % % decomp.m, solve.m % %---------------------------------------------------------------------% n = length(A(:,1)); [A, rcondA, pvt] = decomp(A); if ((1.0 + rcondA) == 1.0) X=[]; display('singularity is detected.'); return; end X = eye(n); for k=1:n X(:,k) = solve(A, X(:,k), pvt); end