0

I want to programmatically find out when A\b failed (for sparse A) so that I can run some problem-specific logic. Using the backslash operator

A\b

I get warnings printed to the console but I want to know about these conditions (singular or nearly singular) programmatically so I can do some problem-specific stuff.

For dense systems, I can do

[soln, cond_recip] = linsolve(A,b);
if cond_recip < 1e-15, ..., end

But linsolve does not work for sparse matrices and I do not want to densify my matrices.

1 Answer 1

1

Try the following:

%# temporarily set warning to issue errors (maybe there are others?)
s = warning('error', 'MATLAB:nearlySingularMatrix'); %#ok<CTPCT>

try
    x = magic(4)\[34; 34; 34; 34];
catch ME
    disp(ME.message)
    %#.. problem specific stuff..
end

%# restore warning state
warning(s);
Sign up to request clarification or add additional context in comments.

1 Comment

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.