【问题标题】:Detecting Matlab failure to solve sparse linear system检测Matlab未能解决稀疏线性系统
【发布时间】:2013-04-26 15:28:53
【问题描述】:

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

A\b

我在控制台上打印了警告,但我想以编程方式了解这些条件(单数或近乎单数),以便我可以做一些针对特定问题的事情。

对于密集系统,我可以做到

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

但是 linsolve 不适用于稀疏矩阵,我不想使矩阵变密。

【问题讨论】:

    标签: matlab linear-algebra


    【解决方案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);
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-03-26
    • 2013-08-25
    • 1970-01-01
    • 2017-06-26
    • 2015-08-07
    • 2023-03-13
    • 1970-01-01
    相关资源
    最近更新 更多