Liking cljdoc? Tell your friends :D
Clojure only.

fastmath.solver.polyroot

All the complex roots of a polynomial with real or complex coefficients.

The roots are found simultaneously by a modified Laguerre iteration (Aberth's correction for the roots already known is applied to the Laguerre step), started from points on circles whose radii come from the Newton polygon of the coefficients. The iteration of a root ends when the backward error of the root, the relative size of the polynomial value, is within the rounding error. The method follows T. R. Cameron, An effective implementation of a modified Laguerre method for the roots of a polynomial, Numerical Algorithms 82 (2019). The polynomial is evaluated in its reversed form for the roots outside of the unit circle, so large coefficients and roots do not overflow.

All the complex roots of a polynomial with real or complex coefficients.

The roots are found simultaneously by a modified Laguerre iteration (Aberth's correction for the roots already known is applied to the Laguerre step), started from points on circles whose radii come from the Newton polygon of the coefficients. The iteration of a root ends when the backward error of the root, the relative size of the polynomial value, is within the rounding error. The method follows T. R. Cameron, An effective implementation of a modified Laguerre method for the roots of a polynomial, Numerical Algorithms 82 (2019). The polynomial is evaluated in its reversed form for the roots outside of the unit circle, so large coefficients and roots do not overflow.
raw docstring

polyrootclj

(polyroot coeffs)
(polyroot coeffs options)

Finds all the complex roots of a polynomial.

Parameters:

  • coeffs: the coefficients c0, c1, ..., cn in ascending order of the power (the polynomial c0 + c1 z + ... + cn z^n, the order of fastmath.polynomials/polynomial), as a sequence or an array, or a polynomial object of fastmath.polynomials. A coefficient is a real number, a Vec2 (the complex number re + i im) or a pair [re im]. All coefficients have to be finite.
  • options (map, optional):
    • :max-iters - limit of the iterations, the sweeps over the roots not converged yet, default 1200.
    • :info? - when truthy, returns the map described below instead of the vector of roots. Default false.

Returns a vector of the n roots as Vec2 (the complex numbers), each root repeated according to its multiplicity (a multiple root is found with the accuracy of the order of the root of the machine epsilon of the multiplicity). Leading zero coefficients are dropped, trailing zero coefficients give exact zero roots, a constant gives no roots.

Order: for real coefficients the real roots in ascending order, then the pairs of complex conjugates by the real part of the pair with the positive imaginary part first; the conjugates are exact and a root whose imaginary part is within the backward error of zero is real. For complex coefficients by the real part, then the imaginary part.

With :info? returns the map {:roots :backward-errors :condition-numbers :converged? :iterations :status}. The vectors have the order of :roots. A backward error is |p(z)| / sum |c_k| |z|^k of the root, the smallest relative perturbation of the coefficients for which z is an exact root; a condition number sum |c_k| |z|^k / (|z| |p'(z)|) is the factor between the relative perturbation of the coefficients and the relative error of the root; the product bounds the relative error of the root. A zero root has the condition number Infinity. :converged? is a vector of booleans. The status is :converged, :max-evals (the iteration limit is reached) or :diverged (a value is not finite).

Throws ex-info for an invalid argument (an empty or zero polynomial, an invalid coefficient: the data holds its :index, never the coefficients). A polynomial whose roots did not converge throws with the status :max-evals or :diverged and the number of the roots not converged as :unconverged; with :info? the status is returned.

See also fastmath.solver/cubic, fastmath.solver/quadratic, fastmath.solver/find-roots.

Finds all the complex roots of a polynomial.

Parameters:

- `coeffs`: the coefficients `c0, c1, ..., cn` in ascending order of the power (the polynomial `c0 + c1 z + ... + cn z^n`, the order of [[fastmath.polynomials/polynomial]]), as a sequence or an array, or a polynomial object of `fastmath.polynomials`. A coefficient is a real number, a `Vec2` (the complex number `re + i im`) or a pair `[re im]`. All coefficients have to be finite.
- `options` (map, optional):
    - `:max-iters` - limit of the iterations, the sweeps over the roots not converged yet, default `1200`.
    - `:info?` - when truthy, returns the map described below instead of the vector of roots. Default `false`.

Returns a vector of the `n` roots as `Vec2` (the complex numbers), each root repeated according to its multiplicity (a multiple root is found with the accuracy of the order of the root of the machine epsilon of the multiplicity). Leading zero coefficients are dropped, trailing zero coefficients give exact zero roots, a constant gives no roots.

Order: for real coefficients the real roots in ascending order, then the pairs of complex conjugates by the real part of the pair with the positive imaginary part first; the conjugates are exact and a root whose imaginary part is within the backward error of zero is real. For complex coefficients by the real part, then the imaginary part.

With `:info?` returns the map `{:roots :backward-errors :condition-numbers :converged? :iterations :status}`. The vectors have the order of `:roots`. A backward error is `|p(z)| / sum |c_k| |z|^k` of the root, the smallest relative perturbation of the coefficients for which `z` is an exact root; a condition number `sum |c_k| |z|^k / (|z| |p'(z)|)` is the factor between the relative perturbation of the coefficients and the relative error of the root; the product bounds the relative error of the root. A zero root has the condition number `Infinity`. `:converged?` is a vector of booleans. The status is `:converged`, `:max-evals` (the iteration limit is reached) or `:diverged` (a value is not finite).

Throws `ex-info` for an invalid argument (an empty or zero polynomial, an invalid coefficient: the data holds its `:index`, never the coefficients). A polynomial whose roots did not converge throws with the status `:max-evals` or `:diverged` and the number of the roots not converged as `:unconverged`; with `:info?` the status is returned.

See also [[fastmath.solver/cubic]], [[fastmath.solver/quadratic]], [[fastmath.solver/find-roots]].
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