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: boolEvaluate outside [x₀, x_m] by extending the end pieces (otherwise NaN).
Implementations§
Source§impl BPoly
impl BPoly
Sourcepub fn new(
c: Array2<f64>,
x: Vec<f64>,
extrapolate: bool,
) -> Result<BPoly, ErrorsJSL>
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.
Sourcepub fn evaluate_derivative(&self, v: f64, nu: usize) -> f64
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}.
Sourcepub fn derivative(&self, nu: usize) -> BPoly
pub fn derivative(&self, nu: usize) -> BPoly
The derivative of order nu, of degree k − nu (degree 0 and value 0 if nu > k).
Sourcepub fn antiderivative(&self, nu: usize) -> BPoly
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.
Sourcepub fn integrate(&self, a: f64, b: f64) -> f64
pub fn integrate(&self, a: f64, b: f64) -> f64
∫_a^b p(x) dx (clamped to the breakpoints unless extrapolating).
Sourcepub fn raise_degree(&self, d: usize) -> BPoly
pub fn raise_degree(&self, d: usize) -> BPoly
The same polynomials in the Bernstein basis of degree k + d (degree elevation).
Sourcepub fn from_power_basis(pp: &PPoly) -> BPoly
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)ⁱ.
Sourcepub fn to_power_basis(&self) -> PPoly
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.
Sourcepub fn from_derivatives(
xi: &[f64],
yi: &[Vec<f64>],
orders: Option<&[usize]>,
) -> Result<BPoly, ErrorsJSL>
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.