Function reference · Solving
roots
Returns the roots of a polynomial as a vector.
It works like Nerdamer 1.x's roots. For new code, solve returns a solution set and handles more than polynomials.
For a number, it returns its two square roots.
Numerical roots use Aberth's method. Pass jenkinstraub as the third argument to use the Jenkins-Traub method instead.
Notation
roots(expression[, variable[, method]])
Write it in an expression: nerdamer('roots(x^2-1,x)'), or in the Playground.
nerdamer.roots
nerdamer.roots(expression: ExpressionInput, variable?: ExpressionInput, method?: ExpressionInput): Vector
A method on the default import. Arguments can be strings, as in Notation.
import { roots }
import { roots } from 'nerdamer/solve';
roots(expression: ExpressionInput, variable?: ExpressionInput, method?: ExpressionInput): Vector
Import only this function, from nerdamer/solve.
Parameters
expression- Univariate polynomial or numeric constant whose roots should be returned.
variable- Optional polynomial variable.
method- Optional numerical polynomial algorithm: aberth (default) or jenkinstraub.
Examples
With the Jenkins-Traub method instead of the default, Aberth's method.
roots(x^3-2,x,jenkinstraub)
// → [1.2599210498948731648, -0.62996052494743658238+1.0911236359717214036*i, -0.62996052494743658238-1.0911236359717214036*i]Open in PlaygroundGood to know
jenkinstraubneeds real coefficients:roots(x^2+i,x,jenkinstraub)is an error. Leave the method out to use Aberth's method, which handles complex coefficients.- Only
rootstakes a method;solvedoesn't. - A comparison such as
x^2<4is an error.
