%% Linear System with Singular Matrix
% Solve a linear system of equations A*x = b involving a singular matrix, A.

A = magic(4);
b = [34; 34; 34; 34];
x = A\b

% When rcond is between 0 and eps, MATLAB® issues a nearly singular warning, but proceeds with the calculation. When working with ill-conditioned matrices, an unreliable solution can result even though the residual (b-A*x) is relatively small. In this particular example, the norm of the residual is zero, and an exact solution is obtained, although rcond is small.
%
% When rcond is equal to 0, the singular warning appears.

A = [1 0; 0 0];
b = [1; 1];
x = A\b

% In this case, division by zero leads to computations with Inf and/or NaN, making the computed result unreliable.
% Copyright 2012 The MathWorks, Inc.