Main Content

Quotient and remainder

`[`

divides `Q`

,`R`

] =
quorem(`A`

,`B`

,`var`

)`A`

by `B`

and
returns the quotient `Q`

and remainder `R`

of
the division, such that `A = Q*B + R`

. This syntax
regards `A`

and `B`

as polynomials
in the variable `var`

.

If `A`

and `B`

are matrices, `quorem`

performs elements-wise division, using `var`

as a variable. It
returns the quotient `Q`

and remainder `R`

of
the division, such that `A = Q.*B + R`

.

`[`

uses
the variable determined by `Q`

,`R`

] =
quorem(`A`

,`B`

)`symvar(A,1)`

. If `symvar(A,1)`

returns
an empty symbolic object `sym([])`

, then `quorem`

uses
the variable determined by `symvar(B,1)`

.

If both `symvar(A,1)`

and `symvar(B,1)`

are
empty, then `A`

and `B`

must
both be integers or matrices with integer elements. In this case, `quorem(A,B)`

returns
symbolic integers `Q`

and `R`

,
such that `A = Q*B + R`

. If `A`

and `B`

are
matrices, then `Q`

and `R`

are
symbolic matrices with integer elements, such that ```
A = Q.*B
+ R
```

, and each element of `R`

is smaller
in absolute value than the corresponding element of `B`

.

Compute the quotient and remainder of the division
of these multivariate polynomials with respect to the variable `y`

:

syms x y p1 = x^3*y^4 - 2*x*y + 5*x + 1; p2 = x*y; [q, r] = quorem(p1, p2, y)

q = x^2*y^3 - 2 r = 5*x + 1

Compute the quotient and remainder of the division of these univariate polynomials:

syms x p = x^3 - 2*x + 5; [q, r] = quorem(x^5, p)

q = x^2 + 2 r = - 5*x^2 + 4*x - 10

Compute the quotient and remainder of the division of these integers:

[q, r] = quorem(sym(10)^5, sym(985))

q = 101 r = 515