divisors
Divisors of integer or expression
Description
Examples
Divisors of Integers
Find all nonnegative divisors of these integers.
Find the divisors of integers. You can use double precision numbers or numbers
converted to symbolic objects. If you call divisors
for a
double-precision number, then it returns a vector of double-precision
numbers.
divisors(42)
ans = 1 2 3 6 7 14 21 42
Find the divisors of negative integers. divisors
returns
nonnegative divisors for negative integers.
divisors(-42)
ans = 1 2 3 6 7 14 21 42
If you call divisors
for a symbolic number, it returns a
symbolic vector.
divisors(sym(42))
ans = [ 1, 2, 3, 6, 7, 14, 21, 42]
The only divisor of 0
is 0
.
divisors(0)
ans = 0
Divisors of Univariate Polynomials
Find the divisors of univariate polynomial expressions.
Find the divisors of this univariate polynomial. You can specify the polynomial as a symbolic expression.
syms x divisors(x^4 - 1, x)
ans = [ 1, x - 1, x + 1, (x - 1)*(x + 1), x^2 + 1, (x^2 + 1)*(x - 1),... (x^2 + 1)*(x + 1), (x^2 + 1)*(x - 1)*(x + 1)]
You also can use a symbolic function to specify the polynomial.
syms f(t) f(t) = t^5; divisors(f,t)
ans(t) = [ 1, t, t^2, t^3, t^4, t^5]
When finding the divisors of a polynomial, divisors
does
not return the divisors of the constant factor.
f(t) = 9*t^5; divisors(f,t)
ans(t) = [ 1, t, t^2, t^3, t^4, t^5]
Divisors of Multivariate Polynomials
Find the divisors of multivariate polynomial expressions.
Find the divisors of the multivariate polynomial expression. Suppose that
u
and v
are variables, and
a
is a symbolic parameter. Specify the variables as a
symbolic vector.
syms a u v divisors(a*u^2*v^3, [u,v])
ans = [ 1, u, u^2, v, u*v, u^2*v, v^2, u*v^2, u^2*v^2, v^3, u*v^3, u^2*v^3]
Now, suppose that this expression contains only one variable (for example,
v
), while a
and u
are symbolic parameters. Here, divisors
treats the
expression a*u^2
as a constant and ignores it, returning only
the divisors of v^3
.
divisors(a*u^2*v^3, v)
ans = [ 1, v, v^2, v^3]
Input Arguments
Tips
divisors(0)
returns0
.divisors(expr,vars)
does not return the divisors of the constant factor when finding the divisors of a polynomial.If you do not specify polynomial variables,
divisors
returns as many divisors as it can find, including the divisors of constant symbolic expressions. For example,divisors(sym(pi)^2*x^2)
returns[ 1, pi, pi^2, x, pi*x, pi^2*x, x^2, pi*x^2, pi^2*x^2]
whiledivisors(sym(pi)^2*x^2, x)
returns[ 1, x, x^2]
.For rational numbers,
divisors
returns all divisors of the numerator divided by all divisors of the denominator. For example,divisors(sym(9/8))
returns[ 1, 3, 9, 1/2, 3/2, 9/2, 1/4, 3/4, 9/4, 1/8, 3/8, 9/8]
.
Version History
Introduced in R2014b