Finding Roots
The root of a function is the value at which the function equals zero.
polyroots(v)—Returns a vector containing the roots of the polynomial whose coefficients are in v.
By default, polyroots uses the LaGuerre method which is iterative and searches for solutions in the complex plane.
root(f(var1, var2, ...), var1, [a, b])—Returns the value of var1 to make the function f equal to zero. If a and b are specified, root finds var1 on the interval [a, b]. Otherwise, var1 must be defined with a guess value before root is called. When a guess value is used, root uses the secant or Mueller’s method; in the case where root bracketing is used, root uses Ridder’s or Brent’s method.
Arguments
f is a scalar-valued function of any number of variables.
var1 is a scalar variable found in f, the variable with respect to which the root is found. Define a complex guess to solve for a complex root.
a, b (optional) are real numbers, a < b, such that f(a) and f(b) have opposite signs. root searches for a root on the interval a≤x ≤ b.
You must specify the range arguments [a, b] when evaluating the root function symbolically.
v is a vector containing coefficients of a polynomial in which the first element is the constant term, and 2 ≤ length(v) ≤ 99.
Additional Information
Inserting the root function from the Ribbon automatically assigns it the Keyword label.
The root function can only solve one equation in one unknown. To solve several equations simultaneously, use find or minerr.
The root function is dependent on TOL, but does not respond to a TOL that is larger than 10-5. This is the maximum convergence criteria. In addition, values of TOL smaller than 10-12 are not likely to produce superior results, while the algorithm may fail to converge.
For functions with multiple roots, the returned root depends on the guess value. If the guess value is very close to a minimum or maximum of f, the root function may fail to converge or converge to a root far away from the guess value. In choosing an appropriate guess value or brackets, it helps to graph the function beforehand.
Functions with rapid variation can cause the root solver to return tiny complex parts even when a real result is expected.
To solve an equation of the form f(x) = g(x), use an expression like x0 := root(f(x) − g(x), x)
For an expression f(x) with a known root r, solving for additional roots of f(x) is equivalent to solving for roots of h(x) = f(x) / (x − r). Dividing out known roots like this is useful for resolving two roots that may be close together. It is often easier to solve for roots of h(x) as defined here than it is to try to find other roots for f(x) with different guesses.
If f(x) has a small slope near its root, then root(f(x), x) may converge to a value r that is relatively far from the actual root. In such cases, even though |f(r)|< TOL, r may be far from the point where f(r) = 0. To find a more accurate root, decrease the value of TOL. Or, try finding root(g(x),x), where g(x) = [f(x))]/[(d/dx)*f(x)]).
The root function may fail to converge, or may converge to an unexpected root, if:
There are no roots to the expression.
The roots are too far from the initial guess.
There is a local maximum, a local minimum, or a discontinuity between the guess value and the roots.
The guess value is very close to a minimum or a maximum of function f.
The expression has a complex root but the initial guess is real (or vice versa).
There are multiple closely-spaced roots—Try reducing the value of TOL to distinguish between them.
The roots are in flat regions of the function—Try reducing the value of TOL, or finding the root of the f(x) function divided by its first derivative.
Was this helpful?