Skip to main content

BPoly

Struct BPoly 

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

A piecewise polynomial of degree k on m intervals in the Bernstein basis.

Fields§

§c: Array2<f64>

Coefficients, shape (k + 1, m): c[a][j] multiplies b_{a,k} on interval j.

§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 BPoly

Source

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

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

Source

pub fn degree(&self) -> usize

The degree k.

Source

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

The nu-th derivative at v: the coefficients are differenced nu times (c'_a = k (c_{a+1} − c_a)/h), then de Casteljau’s algorithm evaluates the result by repeated convex combinations c_a ← (1 − s) c_a + s c_{a+1}.

Source

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

The value at v.

Source

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

The derivative of order nu, of degree k − nu (degree 0 and value 0 if nu > k).

Source

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

The antiderivative of order nu, zero at x₀ and continuous (SciPy’s antiderivative). Once: C_{a+1} = h (c₀ + … + c_a)/(k + 1), C₀ = 0 on each interval; since only the last Bernstein polynomial is non-zero at the right end, adding the running sum of the last coefficients of the earlier intervals makes the pieces join up.

Source

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

∫_a^b p(x) dx (clamped to the breakpoints unless extrapolating).

Source

pub fn raise_degree(&self, d: usize) -> BPoly

The same polynomials in the Bernstein basis of degree k + d (degree elevation).

Source

pub fn from_power_basis(pp: &PPoly) -> BPoly

From the power basis (SciPy’s BPoly.from_power_basis): c_a = Σ_{i ≤ a} C(a, i)/C(k, i) hⁱ pᵢ with pᵢ the coefficient of (x − x_j)ⁱ.

Source

pub fn to_power_basis(&self) -> PPoly

To the power basis (SciPy’s PPoly.from_bernstein_basis), by expanding sᵃ (1 − s)^{k−a} binomially.

Source

pub fn from_derivatives( xi: &[f64], yi: &[Vec<f64>], orders: Option<&[usize]>, ) -> Result<BPoly, ErrorsJSL>

The piecewise polynomial matching given derivatives at the breakpoints (SciPy’s BPoly.from_derivatives): yi[i] lists f(xᵢ), f'(xᵢ), …. On each interval the Bernstein coefficients follow from the end values one at a time, since the q-th derivative at the left end involves only the first q + 1 coefficients (and at the right end only the last). With orders, interval i matches only enough derivatives for a polynomial of that degree, split between the ends. All pieces are raised to the degree of the interval with the most derivatives given, as in SciPy.

Trait Implementations§

Source§

impl Clone for BPoly

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 BPoly

Source§

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

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

impl PartialEq for BPoly

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 BPoly

Auto Trait Implementations§

§

impl Freeze for BPoly

§

impl RefUnwindSafe for BPoly

§

impl Send for BPoly

§

impl Sync for BPoly

§

impl Unpin for BPoly

§

impl UnsafeUnpin for BPoly

§

impl UnwindSafe for BPoly

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.