factor

Factorization

Syntax

Description

example

F = factor(x) returns all irreducible factors of x in vector F. If x is an integer, factor returns the prime factorization of x. If x is a symbolic expression, factor returns the subexpressions that are factors of x.

example

F = factor(x,vars) returns an array of factors F, where vars specifies the variables of interest. All factors not containing a variable in vars are separated into the first entry F(1). The other entries are irreducible factors of x that contain one or more variables from vars.

Examples

Factor an Integer

F = factor(823429252)
F =
           2           2          59         283       12329

To factor integers greater than flintmax, convert the integer to a symbolic object using sym. Then place the number in quotation marks to represent it accurately.

F = factor(sym('82342925225632328'))
F =
[ 2, 2, 2, 251, 401, 18311, 5584781]

To factor a negative integer, convert it to a symbolic object using sym.

F = factor(sym(-92465))
F =
[ -1, 5, 18493]

Perform Prime Factorization of a Large Number

Perform prime factorization for 41758540882408627201. Since the integer is greater than flintmax, convert it to a symbolic object using sym, and place the number in quotation marks to represent it accurately.

n = sym('41758540882408627201');
factor(n)
ans =
[ 479001599, 87178291199]

Factor a Symbolic Fraction

Factor the fraction 112/81 by converting it into a symbolic object using sym.

F = factor(sym(112/81))
F =
[ 2, 2, 2, 2, 7, 1/3, 1/3, 1/3, 1/3]

Factor a Polynomial

Factor the polynomial x^6-1.

syms x
F = factor(x^6-1)
F =
[ x - 1, x + 1, x^2 + x + 1, x^2 - x + 1]

Factor the polynomial y^6-x^6.

syms y
F = factor(y^6-x^6)
F =
[ -1, x - y, x + y, x^2 + x*y + y^2, x^2 - x*y + y^2]

Separate Factors Containing Specified Variables

Factor y^2*x^2 for factors containing x.

syms x y
F = factor(y^2*x^2,x)
F =
[ y^2, x, x]

factor combines all factors without x into the first element. The remaining elements of F contain irreducible factors that contain x.

Factor the polynomial y for factors containing symbolic variables b and c.

syms a b c d
y = -a*b^5*c*d*(a^2 - 1)*(a*d - b*c);
F = factor(y,[b c])
F =
[ -a*d*(a - 1)*(a + 1), b, b, b, b, b, c, a*d - b*c]

factor combines all factors without b or c into the first element of F. The remaining elements of F contain irreducible factors of y that contain either b or c.

Input Arguments

expand all

x — Input to factornumber | symbolic number | symbolic expression | symbolic function

Input to factor, specified as a number, or a symbolic number, expression, or function.

vars — Variables of interestsymbolic variable | vector of symbolic variables

Variables of interest, specified as a symbolic variable or a vector of symbolic variables. Factors that do not contain a variable specified in vars are grouped into the first element of F. The remaining elements of F contain irreducible factors of x that contain a variable in vars.

Output Arguments

expand all

F — Factors of inputsymbolic vector

Factors of input, returned as a symbolic vector.

More About

expand all

Tips

  • To factor an integer greater than flintmax, wrap the integer with sym. Then place the integer in quotation marks to represent it accurately, for example, sym('465971235659856452').

  • To factor a negative integer, wrap the integer with sym, for example, sym(-3).

Was this topic helpful?