PolyDyn

Struct PolyDyn 

Source
pub struct PolyDyn { /* private fields */ }
Expand description

A polynomial of dynamic degree.

It would be nice to have polynomials of type-level degree, but that’s a bit awkward without const generic expressions (e.g. to express the type of the derivative). It could be done with typenum and generic_array

Implementations§

Source§

impl PolyDyn

Source

pub fn new(coeffs: impl IntoIterator<Item = f64>) -> Self

Constructs a new polynomial from coefficients.

The first coefficient provided will be the constant term, the second will be the linear term, and so on.

Source

pub fn coeffs(&self) -> &[f64]

The coefficients of this polynomial.

In the returned slice, the coefficient of x^i is at index i.

Source

pub fn deriv(&self) -> PolyDyn

Returns the polynomial that’s the derivative of this polynomial.

Source

pub fn eval(&self, x: f64) -> f64

Evaluates this polynomial at a point.

Source

pub fn degree(&self) -> usize

The degree of this polynomial.

This function only looks at the presence of coefficients, not their value. If you construct a polynomial with three coefficients, this method will say that it has degree 2 even if all of those coefficients are zero.

A polynomial with no coefficients will give zero as its degree, as will a polynomial with one coefficient.

Source

pub fn roots_between(&self, lower: f64, upper: f64, x_error: f64) -> Vec<f64>

Finds all the roots in an interval, using Yuksel’s algorithm.

This is a numerical, iterative method. It first constructs critical points to find bracketing intervals (intervals [x0, x1] where self.eval(x0) and self.eval(x1) have different signs). Then it uses a kind of modified Newton method to find a root on each bracketing interval. It has a few limitations:

  • if there is only a small interval where the polynomial changes sign, it can miss roots. For example, when two roots are very close together it can miss them both.
  • run time is quadratic in the degree. However, it is often very fast in practice for polynomials of low degree, especially if the interval [lower, upper] contains few roots.
Source

pub fn roots_between_with_buffer( &self, lower: f64, upper: f64, x_error: f64, out: &mut Vec<f64>, scratch: &mut Vec<f64>, )

Finds all the roots in an interval, using Yuksel’s algorithm.

See PolyDyn::roots_between for more details. This method differs from that one in that it performs fewer allocations: you provide an out buffer for the result and a scratch buffer for intermediate computations.

Trait Implementations§

Source§

impl Clone for PolyDyn

Source§

fn clone(&self) -> PolyDyn

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for PolyDyn

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Mul<&PolyDyn> for PolyDyn

Source§

type Output = PolyDyn

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: &PolyDyn) -> PolyDyn

Performs the * operation. Read more
Source§

impl<'a> Mul for &'a PolyDyn

Source§

type Output = PolyDyn

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: &PolyDyn) -> PolyDyn

Performs the * operation. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.