packages

interpolate::ops

On this page

Notation for calculus on interpolants (feature ops, on by default):

∂(s), ∂(s, n) derivative of a spline or polynomial, as a spline or polynomial (autodiff's ∂, also for functions) ∇(a) gradient of samples on a unit grid, as samples (autodiff's ∇, also for functions) ∫(f, a..b) definite integral of a function (adaptive quadrature) a ≈ b approximately equal, for floats and arrays (==) s ⊗ t tensor product of two 1-d splines (linalg's ⊗)

∂ and ∇ are autodiff's, re-exported: they give the derivative in the form of what they are given, never a value at a point (∂(s)(x) is the value), and this module only adds the interpolants to them, so it imports together with optimize's ops. ∘, +, -, *, /, %, ** on Polynomial come from core's operator traits and need no feature.

Re-exports

autodiff::ops::{Derive, Gradient, ∂, ∇}Source

pub use autodiff::ops::{Derive, Gradient, ∂, ∇}
  • Derive
  • Gradient
  • ∂
  • ∇

Traits

IntegrandSource

pub trait Integrand

What ∫ integrates: a function or closure (adaptive quadrature) or an interpolant (exactly when it is piecewise polynomial).

ApproxSource

pub trait Approx<Rhs = Self>

a ≈ b: equal up to rounding, |a - b| <= 1e-9 max(1, |a|, |b|) for every element (core's is_close with rel and abs both 1e-9), arrays of the same shape only. Binds like == and cannot chain. The named form with a tolerance is close.

nabi
use interpolate::ops::Approx;
use core::array::Vector;

assert(0.1 + 0.2 ≈ 0.3);
let x: Vector<f64> = [1, 2];
assert(x .* 3.0 ./ 3.0 ≈ x);
assert(!(1.0 ≈ 1.001));
assert(1.0.close(1.001, 0.01));
  • fn approx(self, rhs: Rhs) -> bool§

    Source

    close(rhs, 1e-9).

  • fn close(self, rhs: Rhs, tol: f64) -> bool§

    Source

    Equal within tol relative to max(1, |a|, |b|).

Functions

∫Source

pub fn ∫<F: Integrand>(f: F, r: Range<f64>) throws (InterpError) -> f64

∫(f, a..b): the definite integral of a function or closure by adaptive Gauss-Kronrod (quad; call quad to read the error estimate), or of an interpolant: splines, Linear and Polynomial exactly (their integrate), the others by quad. Infinite ends work for functions: ∫(f, 0.0..f64::INFINITY).

nabi
use interpolate::ops::∫;

assert((try ∫(f64::sin, 0.0..f64::PI) - 2.0).abs() < 1e-14);
let k = 2.0;
assert((try ∫(|x: f64| -> f64 { (-k * x * x).exp() }, 0.0..f64::INFINITY) - 0.6266570686577501).abs() < 1e-12);
let s = try interpolate::cubic_spline([0, 1, 2, 3], [0, 1, 8, 27]);
assert(try ∫(s, 0.0..3.0) == s.integrate(0.0..3.0));