%% Suppress Matrix Condition Warnings
% Solve a linear system using linsolve with two outputs to suppress matrix conditioning warnings.
%
% Create a 20-by-20 Hilbert test matrix. This matrix is nearly singular, with the largest singular value being about 2e18 larger than the smallest.

A = hilb(20);

%
% Solve a linear system involving A with linsolve. Since A is nearly singular, linsolve returns a warning.

b = ones(20,1);
x = linsolve(A,b);

%
% Now, solve the same linear system, but specify two outputs to linsolve. MATLAB® suppresses the warning, and the second output r contains the reciprocal condition number of A. You can use this syntax to handle ill-conditioned matrices with special cases in your code, without the code producing a warning.

[x,r] = linsolve(A,b)

% Copyright 2018 The MathWorks, Inc.