[英]Detecting Matlab failure to solve sparse linear system
I want to programmatically find out when A\\b failed (for sparse A) so that I can run some problem-specific logic. 我想以编程方式找出A \\ b何时失败(对于稀疏A),以便我可以运行一些特定于问题的逻辑。 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. 但是linsolve不适用于稀疏矩阵,并且我不想使我的矩阵致密。
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);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.