pooltool.ptmath.roots.core

Functions

get_real_positive_smallest_root(roots: NDArray[complex128], abs_or_rel_cutoff: float = 0.001, rtol: float = 0.001, atol: float = 1e-09) float[source]

Returns the smallest positive and real root from a set of roots.

Parameters:
  • roots : NDArray[complex128]

    A 1D array of n polynomial roots.

  • abs_or_rel_cutoff : float

    The criteria for a root being real depends on the magnitude of its real component. If it’s large, we require the imaginary component to be less than atol in absolute terms. But when the real component is small, we require the imaginary component be less than a fraction, rtol, of the real component. abs_or_rel_cutoff defines a threshold for the magnitude of the real component, above which atol is used and below which rtol is used.

  • atol : float

    A root r (with abs(r.real) >= abs_or_rel_cutoff) is considered real if abs(r.imag) < atol.

  • rtol : float

    A root r (with abs(r.real) < abs_or_rel_cutoff) is considered real if abs(r.imag) / abs(r.real) < rtol. And in the special case when r.real == 0, the root is considered real if r.imag == 0, too.

Returns:

The smallest root that is real and positive. If no such root exists (e.g. all roots are complex or negative), then np.inf is returned.

Return type:

float

get_real_positive_smallest_roots(roots: NDArray[complex128], abs_or_rel_cutoff: float = 0.001, rtol: float = 0.001, atol: float = 1e-09) NDArray[float64][source]

Returns the smallest postive and real root for each set of roots.

Parameters:
  • roots : NDArray[complex128]

    A mxn array of polynomial root solutions, where m is the number of equations and n is the order of the polynomial.

  • abs_or_rel_cutoff : float

    The criteria for a root being real depends on the magnitude of its real component. If it’s large, we require the imaginary component to be less than atol in absolute terms. But when the real component is small, we require the imaginary component be less than a fraction, rtol, of the real component. abs_or_rel_cutoff defines a threshold for the magnitude of the real component, above which atol is used and below which rtol is used.

  • atol : float

    A root r (with abs(r.real) >= abs_or_rel_cutoff) is considered real if abs(r.imag) < atol.

  • rtol : float

    A root r (with abs(r.real) < abs_or_rel_cutoff) is considered real if abs(r.imag) / abs(r.real) < rtol. And in the special case when r.real == 0, the root is considered real if r.imag == 0, too.

Returns:

An array of shape m. Each value is the smallest root that is real and positive. If no such root exists (e.g. all roots are complex), then np.inf is used.

Return type:

NDArray[float64]