Main Content

Remainder after division

Find the remainder after division in case both the dividend and divisor are integers.

Find the modulus after division for these numbers.

[rem(sym(27), 4), rem(sym(27), -4), rem(sym(-27), 4), rem(sym(-27), -4)]

ans = [ 3, 3, -3, -3]

Find the remainder after division in case the dividend is a rational number, and the divisor is an integer.

Find the remainder after division for these numbers.

[rem(sym(22/3), 5), rem(sym(1/2), -7), rem(sym(27/6), -11)]

ans = [ 7/3, 1/2, 9/2]

For vectors and matrices, `rem`

finds
the remainder after division element-wise. Nonscalar arguments must
be the same size.

Find the remainder after division for the elements of these two matrices.

A = sym([27, 28; 29, 30]); B = sym([2, 3; 4, 5]); rem(A,B)

ans = [ 1, 1] [ 1, 0]

Find the remainder after division for the elements of matrix `A`

and
the value `9`

. Here, `rem`

expands `9`

into
the `2`

-by-`2`

matrix with all elements
equal to `9`

.

rem(A,9)

ans = [ 0, 1] [ 2, 3]

Calling

`rem`

for numbers that are not symbolic objects invokes the MATLAB^{®}`rem`

function.All nonscalar arguments must be the same size. If one input arguments is nonscalar, then

`mod`

expands the scalar into a vector or matrix of the same size as the nonscalar argument, with all elements equal to the corresponding scalar.