필터 지우기
필터 지우기

Is this a bug in double precision data type?

조회 수: 1 (최근 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)

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by