[英]Detecting Matlab failure to solve sparse linear system
我想以編程方式找出A \\ b何時失敗(對於稀疏A),以便我可以運行一些特定於問題的邏輯。 使用反斜杠運算符
A\b
我收到警告打印到控制台,但我想以編程方式了解這些情況(單數或幾乎單數),因此我可以做一些特定於問題的事情。
對於密集系統,我可以
[soln, cond_recip] = linsolve(A,b);
if cond_recip < 1e-15, ..., end
但是linsolve不適用於稀疏矩陣,並且我不想使我的矩陣致密。
請嘗試以下操作:
%# 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.