Is this a bug in double precision data type?

3 ビュー (過去 30 日間)
Dingyu Xue
Dingyu Xue 2019 年 5 月 21 日
コメント済み: Dingyu Xue 2019 年 5 月 21 日
Try this
n=7; eye(n)*inf+ones(n)
I got
ans =
Inf NaN NaN NaN NaN NaN NaN
NaN Inf NaN NaN NaN NaN NaN
NaN NaN Inf NaN NaN NaN NaN
NaN NaN NaN Inf NaN NaN NaN
NaN NaN NaN NaN Inf NaN NaN
NaN NaN NaN NaN NaN Inf NaN
NaN NaN NaN NaN NaN NaN Inf
What I am expecting is the off-diaginal ones are 1's, rather than Nan's
  1 件のコメント
Dingyu Xue
Dingyu Xue 2019 年 5 月 21 日
Sorry I made a mistake. The answer is correct. To take the same effect, the infinite term inf should be made to a large finite value, say 1e30. The command should be
>> n=7; A=ones(n)+1e30*eye(n)

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

採用された回答

Josh
Josh 2019 年 5 月 21 日
It's not a bug. What's happening is you're multiplying Inf * 0, which is undefined (it's equivalent to trying to calculate 0/0). Try something like this, it will just set the diagonal elements to Infinity without multiplying the off-diagonal elements by Infinity as well:
n = 7; diag(Inf * ones(n, 1)) + ones(n)
  1 件のコメント
Dingyu Xue
Dingyu Xue 2019 年 5 月 21 日
Thanks, I made a mistake.

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

その他の回答 (0 件)

カテゴリ

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

製品


リリース

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by