factor
Factorization
Description
F = factor(___,Name,Value)Name,Value pair
        arguments. This syntax can use any of the input arguments from the previous syntaxes.
Examples
Factor Integer Numbers
F = factor(823429252)
F =
           2           2          59         283       12329To 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 Large Numbers
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 Symbolic Fractions
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 Polynomials
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.
Choose Factorization Modes
Use the FactorMode argument to choose a particular
          factorization mode.
Factor an expression without specifying the factorization mode. By default,
          factor uses factorization over rational numbers. In this mode,
          factor keeps rational numbers in their exact symbolic form.
syms x factor(x^3 + 2, x)
ans = x^3 + 2
Factor the same expression, but this time use numeric factorization over real numbers. This mode factors the expression into linear and quadratic irreducible polynomials with real coefficients and converts all numeric values to floating-point numbers.
factor(x^3 + 2, x, 'FactorMode', 'real')
ans = [ x + 1.2599210498948731647672106072782,... x^2 - 1.2599210498948731647672106072782*x + 1.5874010519681994747517056392723]
Factor this expression using factorization over complex numbers. In this mode,
          factor reduces quadratic polynomials to linear expressions with
        complex coefficients. This mode converts all numeric values to floating-point
        numbers.
factor(x^3 + 2, x, 'FactorMode', 'complex')
ans = [ x + 1.2599210498948731647672106072782,... x - 0.62996052494743658238360530363911 + 1.0911236359717214035600726141898i,... x - 0.62996052494743658238360530363911 - 1.0911236359717214035600726141898i]
Factor this expression using the full factorization mode. This mode factors the expression into linear expressions, reducing quadratic polynomials to linear expressions with complex coefficients. This mode keeps rational numbers in their exact symbolic form.
factor(x^3 + 2, x, 'FactorMode', 'full')
ans = [ x + 2^(1/3),... x - 2^(1/3)*((3^(1/2)*1i)/2 + 1/2),... x + 2^(1/3)*((3^(1/2)*1i)/2 - 1/2)]
Approximate the result with floating-point numbers by using vpa.
        Because the expression does not contain any symbolic parameters besides the variable
          x, the result is the same as in complex factorization mode.
vpa(ans)
ans = [ x + 1.2599210498948731647672106072782,... x - 0.62996052494743658238360530363911 - 1.0911236359717214035600726141898i,... x - 0.62996052494743658238360530363911 + 1.0911236359717214035600726141898i]
Approximate Results Containing RootOf
        In the full factorization mode,factor also can
          return results as a symbolic sums over polynomial roots expressed as
            RootOf.
Factor this expression.
syms x s = factor(x^3 + x - 3, x, 'FactorMode','full')
s = [ x - root(z^3 + z - 3, z, 1),... x - root(z^3 + z - 3, z, 2),... x - root(z^3 + z - 3, z, 3)]
Approximate the result with floating-point numbers by using
        vpa.
vpa(s)
ans = [ x - 1.2134116627622296341321313773815,... x + 0.60670583138111481706606568869074 + 1.450612249188441526515442203395i,... x + 0.60670583138111481706606568869074 - 1.450612249188441526515442203395i]
Input Arguments
Name-Value Arguments
Output Arguments
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).
Version History
Introduced before R2006a