Skip to main content

PPoly

Struct PPoly 

Source
pub struct PPoly {
    pub c: Array2<f64>,
    pub x: Vec<f64>,
    pub extrapolate: bool,
}
Expand description

A piecewise polynomial of degree k on m intervals.

Fields§

§c: Array2<f64>

Coefficients, shape (k + 1, m); row 0 multiplies the highest power.

§x: Vec<f64>

The m + 1 breakpoints, increasing.

§extrapolate: bool

Evaluate outside [x₀, x_m] by extending the end pieces (otherwise NaN).

Implementations§

Source§

impl PPoly

Source

pub fn new( c: Array2<f64>, x: Vec<f64>, extrapolate: bool, ) -> Result<PPoly, ErrorsJSL>

A piecewise polynomial from coefficients (shape (k + 1, m)) and m + 1 breakpoints.

Source

pub fn degree(&self) -> usize

The degree k.

Source

pub fn evaluate(&self, v: f64) -> f64

The value at v.

Source

pub fn evaluate_derivative(&self, v: f64, nu: usize) -> f64

The nu-th derivative at v.

Source

pub fn derivative(&self, nu: usize) -> PPoly

The derivative of order nu as a piecewise polynomial of degree k − nu (degree 0 and value 0 if nu > k).

Source

pub fn antiderivative(&self, nu: usize) -> PPoly

The antiderivative of order nu, zero at x₀ and continuous with its first nu − 1 derivatives (SciPy’s antiderivative): the coefficients are divided by rising factorials, and the new low-order coefficients of each piece are set from the previous piece’s values at the shared breakpoint.

Source

pub fn integrate(&self, a: f64, b: f64) -> f64

∫_a^b p(x) dx (with extrapolation beyond the breakpoints if enabled).

Source

pub fn solve(&self, y: f64, discontinuity: bool) -> Vec<f64>

The real x with p(x) = y (SciPy’s solve), increasing. Each piece’s roots are the eigenvalues of the companion matrix of its polynomial, kept when real (to a small tolerance) and inside the piece, then polished by Newton steps. With discontinuity, a breakpoint where the polynomial jumps across y is reported too. Pieces that equal y identically are skipped.

Source

pub fn roots(&self) -> Vec<f64>

The real roots, solve(0, true) (SciPy’s roots).

Source

pub fn cubic_hermite( x: &[f64], y: &[f64], dydx: &[f64], ) -> Result<PPoly, ErrorsJSL>

The cubic Hermite interpolant with values y and slopes dydx at the strictly increasing x (SciPy’s CubicHermiteSpline). With h the interval length and s the secant slope, the piece is y₀ + d₀ t + (3s − 2d₀ − d₁)/h · t² + (d₀ + d₁ − 2s)/h² · t³.

Source

pub fn from_spline(spline: &BSpline) -> PPoly

The same function as a B-spline, as pieces between its distinct knots in the base interval [t_k, t_n] (SciPy’s PPoly.from_spline, which also keeps the empty intervals between repeated knots): each piece’s coefficients are the spline’s Taylor coefficients s⁽ⁱ⁾(x_j)/i! at the left end.

Trait Implementations§

Source§

impl Clone for PPoly

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for PPoly

Source§

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

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

impl PartialEq for PPoly

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for PPoly

Auto Trait Implementations§

§

impl Freeze for PPoly

§

impl RefUnwindSafe for PPoly

§

impl Send for PPoly

§

impl Sync for PPoly

§

impl Unpin for PPoly

§

impl UnsafeUnpin for PPoly

§

impl UnwindSafe for PPoly

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> MaybeSerialize for T
where T: ?Sized,

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 = !

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

fn try_from(value: U) -> Result<T, !>

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.