diffrence between rem and mod
Ältere Kommentare anzeigen
mod(4,-10)
ans =
-6
>> rem(4,-10)
ans =
4
guys could you tell me in simple language whats is diffrence between two huh i know mod take the second number symbol but i didnt get the real math out of it
Akzeptierte Antwort
Weitere Antworten (1)
Samiu Haque
am 7 Sep. 2020
0 Stimmen
When mod(4,-10) is used, it works as -10*1=-10 and the remainder becomes 4-10=-6
But when rem(4,-10) is used, it works as -10*0=0 and the remainder becomes 4-0=4
If the dividend and divisor both are positive integers, then rem() and mod() function returns the same result. But if either of them is negative, then mod() function avoid the multiple of zero and return the remainder considering the quotient as 1. This is because the mod() function's output is periodic.
2 Kommentare
Moon Light
am 8 Jan. 2022
mod(4,-3) ans= - 2
Why??
Walter Roberson
am 9 Jan. 2022
(-3*-2) + (- 2) = 4 (-3*-1) + ( 1) = 4
However, when you use mod() and the remainder is not 0 then it will be the same sign as the modulus (second parameter)
Kategorien
Mehr zu Elementary Math finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!