What will be a suitable option to circumvent a non-invertible matrix?

2 ビュー (過去 30 日間)
Aboltabol
Aboltabol 2023 年 9 月 27 日
コメント済み: Aboltabol 2023 年 9 月 28 日
Line 157 of this code-file (relevant part is reproduced below) used to calculate the optical flow between two images occassionally returns an error:
% .........
% Solve this system of linear equations, adding a small value along the
% diagonal to avoid potentially having a singular matrix
diag_small_value = sparse(1:2*N, 1:2*N, 1e-10);
A = A + diag_small_value;
xexact = A\b;
% .........
>>> Warning: Matrix is singular, close to singular or badly scaled. Results may be inaccurate.
So, any downsides to using
pinv(A)*B
under a try-except block? Or, maybe we avoid the iterative computation since we already have the eigen vector though that will be weird .....
  1 件のコメント
Walter Roberson
Walter Roberson 2023 年 9 月 27 日
Note that "Matrix is singular" is a warning not an error, so try ; catch would not catch it.
You can consider testing rcond before using the \ operator.
I do not know anything about the mathematics of optical flow, so I do not know what equations are being solved or why they might give problems.

サインインしてコメントする。

回答 (2 件)

Matt J
Matt J 2023 年 9 月 27 日
The approach is valid if A is symmetric, positive definite, but 1e-10 may not be large enough to add substantial conditioning.
  2 件のコメント
Aboltabol
Aboltabol 2023 年 9 月 27 日
What is typically a good constant to add?
Matt J
Matt J 2023 年 9 月 27 日
編集済み: Matt J 2023 年 9 月 27 日
That depends on the maximum eigenvalue of A. Adding δ will give a new condition number of approximately,
Also, I don't know your application, so I don't know what accuracy you are prepared to sacrifice by modifying A.

サインインしてコメントする。


Bruno Luong
Bruno Luong 2023 年 9 月 27 日
When you encount warning message like this, the first thing to ask is not "how do I change linear inversion algorithm?", but "what condition I forgot to take into account in order for my problem to be wellposed?".
In the optical flow, the answer could be that you forgot to impose some boundary condition so that the flow is uniquely determine.
If you won't fix that, any algorithm will fail to give you the correct answer.
  1 件のコメント
Aboltabol
Aboltabol 2023 年 9 月 28 日

Using custom code but not really seeing what boundary condition is missing.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeOperating on Diagonal Matrices についてさらに検索

製品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by