Warning singular matrix.
5 ビュー (過去 30 日間)
古いコメントを表示
I am using \ to solve a system of linear equations. I get a warning telling me the matrix is singular or ill conditioned. This only happens sometimes as my program is recursive. In the event that this happens, there is a 'fall back value I would like to assign as the solution. How could I implement something like an if statement like:
if(warning) x=this instead end
I was reading about dbstop, but that doesn't seem to do what I want.
Thanks,
Chris
0 件のコメント
回答 (2 件)
the cyclist
2011 年 7 月 5 日
There is the try() command, as part of the try-catch structure, but I think that only works for error-trapping, not warning-trapping. That would be a nice feature.
You should be able to use the lastwarn() command to create something like the same thing. Specifically, I am thinking you could execute the lastwarn() command just after your code, and use the output to determine whether to assign your "fall back" value.
0 件のコメント
Sean de Wolski
2011 年 7 月 5 日
You could check if any of the result isinf
if any(isinf(result(:))) %is it singular?
x = this_instead; %yeah, doh!
end
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Numeric Types についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!