This is a `playground`

to test code. It runs a full `Node.js`

environment and already has all of `npm`

’s 400,000 packages pre-installed, including `minimatrix-polyroots`

with all `npm`

packages installed. **Try it out**:

var minimatrixPolyroots = require("minimatrix-polyroots")

- all documents on RunKit are public
`require()`

any package directly from npm- use arrow functions, classes, template strings, and most of ES6
`await`

any promise instead of using callbacks (example)- create your own embedded
**node.js**snippets

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

Implementation of Kahan's polynomial root finders for polynomials up to degree 4.

According to Kahan, standard cubic root finders based on classical methods are prone to numerical inaccuracies. This is an implementation of a numerically stable method illustrated in Kahan's notes titled "To Solve a Real Cubic Equation".

The notes can be found here: http://people.eecs.berkeley.edu/~wkahan/Math128/Cubic.pdf.

Kahan's cubic root finder is based on a quadratic root finder. In like fashion, the quartic root finder is based on Kahan's cubic root finder. The linear root finder is easy to calculate and is added for completeness.

The linear equation solved is Ax + B = 0.

The quadratic equation solved is Ax^{2} + Bx + C = 0.

The cubic equation solved is Ax^{3} + Bx^{2} + Cx + D = 0.

The quartic equation solved is Ax^{4} + Bx^{3} + Cx^{2} + Dx + E = 0.

- getLinearRoot(A, B)
- getQuadraticRoots(A, B, C)
- getCubicRoots(A, B, C, D)
- getQuarticRoots(A, B, C, D, E)

The roots returned are in an unsorted array. Since roots can be complex, they are given in a complex form:

```
[
{
real: <number>,
imag: <number>
}
...
]
```

Algorithm and pseudocode by William Kahan. Implementation in Javascript by Tim Bright.

(c) Tim Bright, 2017. MIT License.

- package on npmhttps://npmjs.com/package/minimatrix-polyroots
- homepagehttps://github.com/tab58/minimatrix-polyroots#readme
- licenseMIT

RunKit is a free, in-browser JavaScript dev environment for prototyping **Node.js** code, with every **npm** package installed. Sign up to share your code.

Sign Up for Free