matlab rank of a matrix

5 ビュー (過去 30 日間)
valentino dardanoni
valentino dardanoni 2022 年 5 月 11 日
編集済み: John D'Errico 2022 年 5 月 11 日
Let R=ones(100,100). Obviously, rank(R) returns 1 for an answer. However, rank(R,1e-20), say, returns 17. Why? Thanks!

採用された回答

John D'Errico
John D'Errico 2022 年 5 月 11 日
編集済み: John D'Errico 2022 年 5 月 11 日
Because the call:
R = ones(100,100);
rank(R,1e-20)
ans = 17
attempts to do something that is demonstrably silly, in terms of double precision arithmetic.
You can try to squeeze blood out of a rock, but when you do, the only blood you will see comes from your own fingers. The default tolerance in rank is set reasonably to produce a valid result in double precision arithmetic. Making it significantly smaller does not make the code work better. Instead, you are fooling yourself.
What does rank do with the tolerance you give it? It essentially counts to see how many singular values of the matrix are sufficiently non-zero, when compared to the size of the maximum singular value.
S = svd(R);
The default tolerance for rank is:
defTol = max(size(R)) * eps(max(S))
defTol = 1.4211e-12
As you can see, it uses that maximum singular value, to then produce a reasonable tolerance for this problem.
sum(S > defTol)
ans = 1
But by setting the tolerance to a far too small number, you create a situation where rank returns something meaningless.

その他の回答 (1 件)

Benjamin Thompson
Benjamin Thompson 2022 年 5 月 11 日
You are probably attempting to go below the numerical precision of your hardware and software:
eps
ans =
2.220446049250313e-16
» help eps
EPS Spacing of floating point numbers.
D = EPS(X), is the positive distance from ABS(X) to the next larger in
magnitude floating point number of the same precision as X.
X may be either double precision or single precision.
For all X, EPS(X) is equal to EPS(ABS(X)).
EPS, with no arguments, is the distance from 1.0 to the next larger double
precision number, that is EPS with no arguments returns 2^(-52).

カテゴリ

Help Center および File ExchangeLinear Algebra についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by