Skip to main content

Cubic

Type Alias Cubic 

Source
pub type Cubic = Poly<4>;
Expand description

A polynomial of degree 3.

Aliased Type§

pub struct Cubic {
    pub(crate) coeffs: [f64; 4],
}

Fields§

§coeffs: [f64; 4]

Implementations§

Source§

impl Cubic

Source

fn critical_points(&self) -> Option<(f64, f64)>

Computes the critical points of this cubic, as long as the discriminant of the derivative is positive. The return values are in increasing order.

Some corner cases worth noting:

  • If the discriminant is zero, returns nothing. That is, we don’t find double-roots of the derivative. These aren’t needed anyway, as these critical points are used to construct bracketing intervals for the roots. Double-roots of the derivative are inflection points of the cubic, and they aren’t needed to bracket roots.
  • If the derivative is linear or close to it, we might return +/- infinity as one of the roots.
  • Unless some input is NaN, we don’t return NaN.
Source

fn rescaled_critical_points(&self) -> Option<(f64, f64)>

Source

fn one_root( &self, lower: f64, upper: f64, lower_val: f64, upper_val: f64, x_error: f64, ) -> f64

Source

fn first_root(self, lower: f64, upper: f64, x_error: f64) -> Option<f64>

Source

pub fn roots_between( self, lower: f64, upper: f64, x_error: f64, ) -> ArrayVec<f64, 3>

Computes all roots between lower and upper, to the desired accuracy.

We make no guarantees about multiplicity. In fact, if there’s a double-root that isn’t a triple-root (and therefore has no sign change nearby) then there’s a good chance we miss it altogether. This is fine if you’re using this root-finding to optimize a quartic, because double-roots of the derivative aren’t local extrema.

Source

pub(crate) fn roots_between_with_buffer<const M: usize>( self, lower: f64, upper: f64, x_error: f64, out: &mut ArrayVec<f64, M>, _scratch: &mut ArrayVec<f64, M>, )