检测Matlab失败解决稀疏线性系统问题

时间:2013-04-26 15:28:54

标签: matlab linear-algebra

我想以编程方式找出A \ b何时失败(对于稀疏A),以便我可以运行一些特定于问题的逻辑。使用反斜杠运算符

A\b

我收到警告打印到控制台但我想以编程方式了解这些条件(单数或近似单数),因此我可以做一些特定问题的事情。

对于密集系统,我可以

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

但linsolve不适用于稀疏矩阵,我不想将我的矩阵加密。

1 个答案:

答案 0 :(得分:1)

尝试以下方法:

%# 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);
相关问题