Modulo with expression not the same as modulo with value

조회 수: 5 (최근 30일)
James
James 2025년 7월 18일
편집: James 2025년 7월 18일
Why does mod(1, Y-X) not approximately equal 0?
mod(1, 0.1)
ans = 0
X = 2;
Y = 2.1;
Y - X
ans = 0.1000
mod(1, Y - X)
ans = 0.1000
I realize that Y - X ~= 0.1 but
isapprox(Y - X, 0.1, "loose")
ans = logical
1
therefore, why not
isapprox(mod(1, Y - X), 0, "loose")
ans = logical
0
My guess is that it is either something to do with floating point precision or the fact that it is an expression vs. a value?

채택된 답변

Matt J
Matt J 2025년 7월 18일
편집: Matt J 2025년 7월 18일
Because mod(1,z) is a discontinuous function of z at 0.1,
fplot(@(z) mod(1,z),[0,0.2])
  댓글 수: 1
James
James 2025년 7월 18일
편집: James 2025년 7월 18일
Ah right, thought I was missing something obvious, thanks.

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

추가 답변 (0개)

카테고리

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

태그

제품


릴리스

R2025a

Community Treasure Hunt

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

Start Hunting!

Translated by