Why am I getting Inf in my matrix

조회 수: 38 (최근 30일)
paul lestingi
paul lestingi . 2018년 4월 1일
댓글: paul lestingi . 2018년 4월 1일
I am trying to divide each position element by element, and every time the denominator = 0 I want to set the result to 1 so I don't get any infinity values (for dividing by zero). When I run the code and test with find(isinf(g)) there are a ton of values that come up as infinity. Can anyone explain why?
clc
close all
x = [0 0 0; 1 2 3;0 2 4];
y = [1 2 0; 2 4 6; 2 4 5];
for u=1:3
for v=1:3
if (x(u,v) == 0)
g(u,v) = 1;
else
g(u,v) =y(u,v)/x(u,v);
end
end
end

채택된 답변

Roger Stafford
Roger Stafford 2018년 4월 1일
편집: Roger Stafford 님. 2018년 4월 1일
It is easily possible for two finite nonzero numbers to have a quotient so large that Matlab must give 'inf' as its value. For example
x = 0.01*realmax;
y = 0.0001;
q = x/y; % <-- This will yield inf for q
I suggest you make a study of the corresponding x and y values that give rise to your inf values to see what kinds of number pairs are involved.
  댓글 수: 1
paul lestingi
paul lestingi 2018년 4월 1일
I'm not sure I understand. There are only two 3x3 matricies being evaluated and by looking at them none of the quotients should be near infinity.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by