@sym: e = factor (n) ¶@sym: [p, m] = factor (n) ¶@sym: g = factor (f) ¶@sym: g = factor (f, x) ¶@sym: g = factor (f, x, y, …) ¶Factor a symbolic polynomial or integer.
A symbolic integer n can be factored:
e = factor(sym(28152))
⇒ e = (sym)
1 3 1 2
17 ⋅2 ⋅23 ⋅3
However, if you want to do anything other than just look at the result, you probably want:
[p, m] = factor(sym(28152)) ⇒ p = (sym) [2 3 17 23] (1×4 matrix) ⇒ m = (sym) [3 2 1 1] (1×4 matrix) prod(p.^m) ⇒ (sym) 28152
An example of factoring a polynomial:
syms x factor(x^2 + 7*x + 12) ⇒ (sym) (x + 3)⋅(x + 4)
When the expression f depends on multiple variables, the second argument x effects what is factored:
syms x y
f = expand((x+3)*(x+4)*(y+5)*(y+6));
factor(f)
⇒ (sym) (x + 3)⋅(x + 4)⋅(y + 5)⋅(y + 6)
factor(f, x, y)
⇒ (sym) (x + 3)⋅(x + 4)⋅(y + 5)⋅(y + 6)
factor(f, x)
⇒ (sym)
⎛ 2 ⎞
(x + 3)⋅(x + 4)⋅⎝y + 11⋅y + 30⎠
factor(f, y)
⇒ (sym)
⎛ 2 ⎞
(y + 5)⋅(y + 6)⋅⎝x + 7⋅x + 12⎠
Passing input x can be useful if your expression f might be a constant and you wish to avoid factoring it as an integer:
f = sym(42); % i.e., a degree-zero polynomial
factor(f) % no, don't want this
⇒ (sym)
1 1 1
2 ⋅3 ⋅7
factor(f, x)
⇒ (sym) 42
See also: @@sym/expand.
Package: symbolic