Roots
Usage Message: Roots[lhs==rhs, var] yields a disjunction of equations which represent the roots of a polynomial
equation. Attributes[Roots] = {Protected} Options: Cubics
-> True Eliminate
-> False EquatedTo
-> Null Modulus
-> 0 Multiplicity
-> 1 Quartics
-> True Using
-> True Notes: Here is an example of the use of the Roots function. The
roots ri are returned using an Or
expression, which is normally displayed in the form r1 || r2 || ....
In[1]:= poly = 16 b^2 x^2-x^6
2 2 6
Out[1]= 16 b x - x
In[2]:= expr = Roots[poly == 0, x]
Out[2]= x == 0 || x == 0 || x == 2 I Sqrt[b] || x == -2 Sqrt[b] ||
> x == -2 I Sqrt[b] || x == 2 Sqrt[b]
You can convert this result into a list of rules, such as might be returned from the Solve
function, using ToRules
.
In[3]:= sol = {ToRules[expr]}
Out[3]= {{x -> 0}, {x -> 0}, {x -> 2 I Sqrt[b]}, {x -> -2 Sqrt[b]},
> {x -> -2 I Sqrt[b]}, {x -> 2 Sqrt[b]}}
The rules can be used to verify that the result gives correct roots of the original polynomial.
In[4]:= poly /. sol
Out[4]= {0, 0, 0, 0, 0, 0}
Roots from polynomials with degree 5 or greater typically cannot be represented in terms of radicals, and are returned using Root
expressions. These expressions can be used much like roots that are given in terms of radicals.
In[5]:= Roots[x^5 + 2x + 1 == 0, x]
5
Out[5]= x == Root[1 + 2 #1 + #1 & , 1] ||
5
x == Root[1 + 2 #1 + #1 & , 2] ||
5
x == Root[1 + 2 #1 + #1 & , 3] ||
5
x == Root[1 + 2 #1 + #1 & , 4] ||
5
x == Root[1 + 2 #1 + #1 & , 5]
It is often convenient to use Root
expressions to represent the result even when the result can be give in terms of radicals, since the Root
expressions are often much more compact. For example, you can use the Cubics
option to cause Roots
to return the roots of this cubic polynomial in the form of Root
expressions, rather than using radicals.
In[6]:= expr = Roots[c0 + c1 x + c2 x^2 + c3 x^3== 0, x, Cubics -> False]
2 3
Out[6]= x == Root[c0 + c1 #1 + c2 #1 + c3 #1 & , 1] ||
2 3
x == Root[c0 + c1 #1 + c2 #1 + c3 #1 & , 2] ||
2 3
x == Root[c0 + c1 #1 + c2 #1 + c3 #1 & , 3]
In this example, since it is mathematically possible to represent these Root
expressions in terms of radicals, you can convert the result into radicals using the ToRadicals
function.
In[7]:= ToRadicals[First[expr]]
-c2 1/3 2
Out[7]= x == ---- - (2 (-c2 + 3 c1 c3)) /
3 c3
3 2
(3 c3 Power[-2 c2 + 9 c1 c2 c3 - 27 c0 c3 +
2 3
Sqrt[4 (-c2 + 3 c1 c3) +
3 2 2
(-2 c2 + 9 c1 c2 c3 - 27 c0 c3 ) ], 1/3]) +
3 2
Power[-2 c2 + 9 c1 c2 c3 - 27 c0 c3 +
2 3
Sqrt[4 (-c2 + 3 c1 c3) +
3 2 2 1/3
(-2 c2 + 9 c1 c2 c3 - 27 c0 c3 ) ], 1/3] / (3 2 c3)
Known Bugs: Roots in Mathematica Version 3.0 can give incorrect results for quartic polynomials with exact coefficients
if the resolvent cubic equation factors into an expression with a numeric factor. This error will also affect functions such as Solve
that use Roots. Although this error has been publicly reported, the affected examples are sufficiently specific that it is unlikely that this error will be encountered by accident. The specificity of the error also makes it relatively easy to write get around it. Here is a simple example of this error. Substituting the result into the original polynomial shows that the solution does not satisfy the equation.
In[1]:= eq = 1 + x + c x^2 + x^3 + x^4
2 3 4
Out[1]= 1 + x + c x + x + x
In[2]:= sol = Solve[eq == 0, x] ;
In[3]:= Simplify[eq /. sol]
3 c 3 c 3 c 3 c
Out[3]= {-------, -------, -------, -------}
3 + 4 c 3 + 4 c 3 + 4 c 3 + 4 c
Here are rules for Roots and for Factor
that cause the problematic numerical factor to be discarded when Factor
is called from Roots.
Unprotect[Roots]
Roots[lhs_ == rhs_, x_, p___] :=
With[{cl = CoefficientList[lhs - rhs, x]},
Block[{result, $QuarticRoots = True},
Print["calling quartic roots rule"];
Roots[lhs == rhs, x, p]
] /; Length[cl] == 5 && FreeQ[cl, x] && !$QuarticRoots]
Unprotect[Factor]
Factor[p_] :=
Block[{result, $QuarticRoots},
result = Factor[p];
If[Head[result] == Times && NumberQ[result[[1]]],
Print["dropping ", result[[1]]]; Drop[result, 1], result]
] /; $QuarticRoots
$QuarticRoots = False
Here is the behavior of this example after loading these rules.
In[9]:= sol = Solve[eq == 0, x] ;
calling quartic roots rule
dropping -1
In[10]:= Simplify[eq /. sol]
Out[10]= {0, 0, 0, 0}
This error has been corrected for the next version of Mathematica.
You can have this workaround automatically loaded by placing
http://support.wolfram.com/mathematica/kernel/Symbols/System/Roots.m
at the location given by
In[11]:= ToFileName[{$TopDirectory,"AddOns", "Autoload",
"Roots", "Kernel"}, "init.m"]
If you have any questions about this behavior, please contact the Technical Support
Group at Wolfram Research.
Additional Online Documentation:
Mathematica 3.0
http://documents.wolfram.com/v3/RefGuide/Roots.html
Mathematica 4.0
http://documents.wolfram.com/v4/RefGuide/Roots.html
Questions or comments? Send email to support@wolfram.com.
| |