The function rem()
calculates the remainder after division. In the equation a = qd + r
, the number q
is the quotient and r
is the remainder. The quotient q
is a natural number, i.e. 0,1,2,3, etc, while the remainder r
is in the range 0<=r<d
. When you call the function rem(a,d)
, it evaluates this expression a-qd<d
for all the natural numbers. When the condition is satisfied, it is output: r=a-qd
.
The arguments can be single numbers, arrays or matrices. For example, if you execute:
a = rem(0:10,3);
b = rem(0:10,4);
c = rem([1 2; 3 4],[4 3; 2 1]);
d = rem(5, 0.1);
e = rem(0.05, 0.1);
You get:
a = [0 1 2 0 1 2 0 1 2 0 1];
b = [0 1 2 3 0 1 2 3 0 1 2];
c = [1 2;1 0];
d = 0;
e = 0.05;