I am having trouble with the if cycle.

조회 수: 1 (최근 30일)
Muhendisleksi
Muhendisleksi 2017년 8월 10일
댓글: Jan 2017년 8월 10일
kontrl = 3.197442310920451e-14
if kontrl>=-10^-20 & kontrl<=10^-20
a = 4
else
a = 10
end
% "a = 4" should be.
  댓글 수: 2
Stephen23
Stephen23 2017년 8월 10일
편집: Stephen23 2017년 8월 10일
@Muhendisleksi: your upper bound is much smaller than kontrl:
>> 10^-20 <= 3.197442310920451e-14
ans = 1
Why do you think that a should be 4 ?
Jan
Jan 2017년 8월 10일
Note: While 10^-20 is an expensive power operation, 1e-20 is a cheap constant.

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

채택된 답변

Walter Roberson
Walter Roberson 2017년 8월 10일
No, that is not correct. "a=4" is given only for values that are in the range +/- 1/10^20 but your value is more than 3000000 times larger than the upper end of that, at roughly +3/10^14
  댓글 수: 2
Muhendisleksi
Muhendisleksi 2017년 8월 10일
편집: Muhendisleksi 2017년 8월 10일
"kontrl" is constantly changing. How can I make this dynamic?
Walter Roberson
Walter Roberson 2017년 8월 10일
a = zeros(1, 100);
for N = 1 : 100
kontrl = randn(1,1) * 1E-20;
if kontrl>=-10^-20 & kontrl<=10^-20
a(N) = 4;
else
a(N) = 10;
end
end
a

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

추가 답변 (0개)

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by