--- layout: default ---

Function polynomialRoot #

Finds the numerical values of the distinct roots of a polynomial with real or complex coefficients. Currently operates only on linear, quadratic, and cubic polynomials using the standard formulas for the roots.

Syntax #

```js math.polynomialRoot(constant, linearCoeff, quadraticCoeff, cubicCoeff) ```

Parameters #

Parameter | Type | Description --------- | ---- | ----------- `coeffs` | ... number | Complex | The coefficients of the polynomial, starting with with the constant coefficent, followed by the linear coefficient and subsequent coefficients of increasing powers.

Returns #

Type | Description ---- | ----------- Array | The distinct roots of the polynomial

Throws #

Type | Description ---- | -----------

Examples #

```js // linear math.polynomialRoot(6, 3) // [-2] math.polynomialRoot(math.complex(6,3), 3) // [-2 - i] math.polynomialRoot(math.complex(6,3), math.complex(2,1)) // [-3 + 0i] // quadratic math.polynomialRoot(2, -3, 1) // [2, 1] math.polynomialRoot(8, 8, 2) // [-2] math.polynomialRoot(-2, 0, 1) // [1.4142135623730951, -1.4142135623730951] math.polynomialRoot(2, -2, 1) // [1 + i, 1 - i] math.polynomialRoot(math.complex(1,3), math.complex(-3, -2), 1) // [2 + i, 1 + i] // cubic math.polynomialRoot(-6, 11, -6, 1) // [1, 3, 2] math.polynomialRoot(-8, 0, 0, 1) // [-1 - 1.7320508075688774i, 2, -1 + 1.7320508075688774i] math.polynomialRoot(0, 8, 8, 2) // [0, -2] math.polynomialRoot(1, 1, 1, 1) // [-1 + 0i, 0 - i, 0 + i] ```

See also #

[cbrt](cbrt.html), [sqrt](sqrt.html)