Liking cljdoc? Tell your friends :D
Clojure only.

fastmath.solver.closed-form

Real roots of polynomials of degree two and three.

quadratic and cubic return the real roots as a vector padded with NaN: the real roots in ascending order, then NaN for each missing one. The coefficients are scaled by powers of two before any product is formed, so the results are correct over the whole range of doubles whenever the roots are representable, and NaN or an infinity otherwise. Polynomials of a lower degree (a leading coefficient equal to zero) are solved as such.

Real roots of polynomials of degree two and three.

[[quadratic]] and [[cubic]] return the real roots as a vector padded with `NaN`: the real roots in ascending order, then `NaN` for each missing one. The coefficients are scaled by powers of two before any product is formed, so the results are correct over the whole range of doubles whenever the roots are representable, and `NaN` or an infinity otherwise. Polynomials of a lower degree (a leading coefficient equal to zero) are solved as such.
raw docstring

cubicclj

(cubic a b c d)

Real roots of the cubic equation a x^3 + b x^2 + c x + d = 0.

Parameters: a, b, c, d (numbers): the coefficients.

Returns a Vec3 [r0 r1 r2] with the real roots in ascending order, NaN after the last real root: one real root gives [r NaN NaN], three real roots (a multiple root is returned as many times as its multiplicity) give all three places. [NaN NaN NaN] is returned when any coefficient is not finite. For a = 0 the equation is quadratic and the result is the result of quadratic followed by NaN. For d = 0 one root is exactly 0.0.

A polynomial which differs from one with a multiple real root by no more than the rounding error of its coefficients is reported with the multiple root (a double root is returned twice, a triple root three times), with a relative accuracy of the root of the order of the square root, respectively the cube root, of the machine epsilon.

The magnitudes of the roots are estimated from the exponents of the coefficients (the Newton polygon) and every group of roots is solved in its own scale: the critical points of the scaled cubic split the line into monotone parts, and the root of every part with a sign change is found by Brent's method. No root is deflated from the polynomial and the coefficients are scaled by powers of two, so the roots keep a small componentwise backward error also when they differ by many orders of magnitude, and the result is correct over the whole range of doubles whenever the roots are representable. A root beyond the range is Infinity, a root below the range is 0.0.

See also quadratic, fastmath.solver/polyroot.

Real roots of the cubic equation `a x^3 + b x^2 + c x + d = 0`.

Parameters: `a`, `b`, `c`, `d` (numbers): the coefficients.

Returns a `Vec3` `[r0 r1 r2]` with the real roots in ascending order, `NaN` after the last real root: one real root gives `[r NaN NaN]`, three real roots (a multiple root is returned as many times as its multiplicity) give all three places. `[NaN NaN NaN]` is returned when any coefficient is not finite. For `a = 0` the equation is quadratic and the result is the result of [[quadratic]] followed by `NaN`. For `d = 0` one root is exactly `0.0`.

A polynomial which differs from one with a multiple real root by no more than the rounding error of its coefficients is reported with the multiple root (a double root is returned twice, a triple root three times), with a relative accuracy of the root of the order of the square root, respectively the cube root, of the machine epsilon.

The magnitudes of the roots are estimated from the exponents of the coefficients (the Newton polygon) and every group of roots is solved in its own scale: the critical points of the scaled cubic split the line into monotone parts, and the root of every part with a sign change is found by Brent's method. No root is deflated from the polynomial and the coefficients are scaled by powers of two, so the roots keep a small componentwise backward error also when they differ by many orders of magnitude, and the result is correct over the whole range of doubles whenever the roots are representable. A root beyond the range is `Infinity`, a root below the range is `0.0`.

See also [[quadratic]], [[fastmath.solver/polyroot]].
raw docstring

quadraticclj

(quadratic a b c)

Real roots of the quadratic equation a x^2 + b x + c = 0.

Parameters: a, b, c (numbers): the coefficients.

Returns a Vec2 [r0 r1] with the real roots in ascending order. A double root is returned twice. NaN fills the places of the missing roots: [NaN NaN] when the roots are not real (negative discriminant), when all the coefficients but c are zero (c = 0 is an identity, c != 0 has no solution, the two cases are not distinguished), and when any coefficient is not finite. For a = 0 the equation is linear and the result is [-c/b NaN].

The coefficients are scaled by a power of two before the discriminant is formed, so the result does not overflow or underflow when the roots are representable. The roots are computed without cancellation, each with a relative error of a few units in the last place.

See also cubic, fastmath.solver/polyroot.

Real roots of the quadratic equation `a x^2 + b x + c = 0`.

Parameters: `a`, `b`, `c` (numbers): the coefficients.

Returns a `Vec2` `[r0 r1]` with the real roots in ascending order. A double root is returned twice. `NaN` fills the places of the missing roots: `[NaN NaN]` when the roots are not real (negative discriminant), when all the coefficients but `c` are zero (`c = 0` is an identity, `c != 0` has no solution, the two cases are not distinguished), and when any coefficient is not finite. For `a = 0` the equation is linear and the result is `[-c/b NaN]`.

The coefficients are scaled by a power of two before the discriminant is formed, so the result does not overflow or underflow when the roots are representable. The roots are computed without cancellation, each with a relative error of a few units in the last place.

See also [[cubic]], [[fastmath.solver/polyroot]].
raw docstring

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
←Move to previous article
→Move to next article
Ctrl+/Jump to the search field
× close