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

A quadratic.

roots(x^2-1,x)
// → [1, -1]
Open in Playground

A cubic.

roots(x^3-x)
// → [1, -1, 0]
Open in Playground

The square roots of a number.

roots(4)
// → [2, -2]
Open in Playground

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 Playground

Good to know

  • jenkinstraub needs 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 roots takes a method; solve doesn't.
  • A comparison such as x^2<4 is an error.

← Back to Function reference