Professional Documents
Culture Documents
Go to function:
mod
Modulus (signed remainder after division)
Syntax
M=m o d ( X , Y )
Definition
m o d ( x , y )is x mod
y.
Description
M=m o d ( X , Y ) returns the remainder X - Y . * f l o o r ( X . / Y ) for nonzero Y , and m o d ( X , Y )always differs from Xby a multiple of Y .
returns Xotherwise.
Remarks
So long as operands Xand Yare of the same sign, the function m o d ( X , Y )returns the same result as does r e m ( X , Y ) . However, for positive Xand Y ,
m o d ( x , y )=r e m ( x , y ) + y
The m o dfunction is useful for congruence relationships: x and y are congruent (mod m) if and only if m o d ( x , m )== m o d ( y , m ) .
Examples
m o d ( 1 3 , 5 ) a n s= 3 m o d ( [ 1 : 5 ] , 3 ) a n s= 1
m o d ( m a g i c ( 3 ) , 3 ) a n s= 2 0 1
1 2 0
0 1 2
Limitations
cens.ioc.ee/local/man/matlab/techdoc/ref/mod.html 1/2
10/7/13
Arguments Xand Yshould be integers. Due to the inexact representation of floating-point numbers on a computer, real (or complex) inputs may lead to unexpected results.
See Also
r e m
cens.ioc.ee/local/man/matlab/techdoc/ref/mod.html
2/2