According to my calculus book: "Every real polynomial can be factored into a product of real (possibly repeated) linear factors and real (also possibly repeated) quadratic factors having no real zeros."
Question: how to do this in Mathematica?
For example: $f(x) = x^5 - 3 x^4 + x^2 - 11 x + 6$
Factor[x^5 - 3 x^4 + x^2 - 11 x + 6]
This doesn't give the desired result (btw, why not?)
Answer
As noted, one sticking point is that polynomial roots in general cannot be represented in Mathematica by anything other than Root[]
objects. Nevertheless, it is possible to do a few manipulations to factorize a real polynomial into its linear and quadratic factors.
decompose[poly_, x_] /; PolynomialQ[poly, x] := Module[{gr, rts},
rts = x /. Solve[poly == 0, x];
gr = GatherBy[rts, {Composition[Unitize, Im],
Composition[RootReduce, Re]}];
Coefficient[poly, x, Exponent[poly, x]]
Apply[Times, Factor[Collect[Times @@ #, x, RootReduce]] & /@
(x - Apply[Join, gr])]]
First, an easy case:
decompose[200 - 448 x + 204 x^2 + 35 x^3 - 89 x^4 + 46 x^5 - 9 x^6 + x^7, x]
(-2 + x) (1/2 (1 - Sqrt[5]) + x) (1/2 (1 + Sqrt[5]) + x)
(25 - 6 x + x^2) (4 - 2 x + x^2)
Here's the OP's example:
decompose[6 - 11 x + x^2 - 3 x^4 + x^5, x]
(x + Root[-6 - 11 #1 - #1^2 + 3 #1^4 + #1^5 &, 1])
(x + Root[-6 - 11 #1 - #1^2 + 3 #1^4 + #1^5 &, 2])
(x + Root[-6 - 11 #1 - #1^2 + 3 #1^4 + #1^5 &, 3])
(x^2 + Root[1296 - 216 #1 + 648 #1^2 + 1566 #1^3 - 1457 #1^4 + 270 #1^5 -
244 #1^6 + 80 #1^7 + 8 #1^8 + #1^10 &, 4] +
x Root[-718 - 1115 #1 + 116 #1^2 + 820 #1^3 + 539 #1^4 + 186 #1^5 + 102 #1^6 +
107 #1^7 + 54 #1^8 + 12 #1^9 + #1^10 &, 3])
Complicated, yes. But N[]
reveals that the Root[]
s are mere algebraic numbers after all:
N[%]
(-3.1838 + x) (-0.552473 + x) (1.53612 + x) (2.2206 - 0.799845 x + x^2)
Comments
Post a Comment