2 unstable releases

0.2.0 Jan 28, 2024
0.1.0 Jan 26, 2024

#163 in Robotics

30 downloads per month

MIT/Apache

53KB
877 lines

gcv_spline - Generalized Cross-Validated Splines for Interpolation and Derivation in Pure Rust

This Rust crate implements the GCV spline, a versatile and easy-to-use spline structure for interpolating data at unknown points and taking accurate derivatives of smooth data.

GCV splines were first developed by Herman J. Woltring. The modules inside the private woltring module are based on his FORTRAN package and a C translation by D. Twisk. Comments from these versions are included in this implementation.


lib.rs:

gcv_spline - Generalized Cross-Validated Splines for Interpolation and Derivation in Pure Rust

This crate implements the GCV spline, a versatile and easy-to-use spline structure for interpolating data at unknown points and taking accurate derivatives of smooth data.

GCV splines were first developed by Herman J. Woltring. The modules inside the private woltring module are based on his FORTRAN package and a C translation by D. Twisk. Comments from these versions are included in this implementation.

Examples

use gcv_spline::GcvSpline;

// Points describe the function y = x**2
// Note that explicit typing is required when using literals
// to facilitate generic type support in gcv_spline
let time: Vec<f64> = vec![0., 1., 3., 4., 5., 6.];
let values = vec![0., 1., 9., 16., 25., 36.];

let spline = GcvSpline::from_data(&time, &values).unwrap();
// Interpolate at a missing point.
// This should be close to the expected value of 4.
assert!((spline.single_point(2.) - 4.).abs() < 1e-12);
// Take derivatives at the interpolated point.
// First derivative should be close to 4.
assert!((spline.point_derivative(2., 1) - 4.).abs() < 1e-12);
// Second derivative should be close to 2.
assert!((spline.point_derivative(2., 2) - 2.).abs() < 1e-12);

Dependencies

~565KB
~11K SLoC