Report a bug
If you spot a problem with this page, click here to create a Github issue.
Improve this page
Quickly fork, edit online, and submit a pull request for this page. Requires a signed-in GitHub account. This works well for small changes. If you'd like to make larger changes you may want to consider using a local clone.

mir.interpolate.pchip

Piecewise Cubic Hermite Interpolating Polynomial

See Also:
Authors:
Ilya Yaroshenko
template pchip(T, size_t N = 1, FirstGridIterator = immutable(T)*, NextGridIterators = Repeat!(N - 1, FirstGridIterator)) if (isFloatingPoint!T && is(T == Unqual!T) && N <= 6)
Constructs piecewise cubic hermite interpolating polynomial with nodes on rectilinear grid.
Examples:
import std.math: approxEqual;
import mir.ndslice.allocation: slice;
import mir.ndslice.slice: sliced;
import mir.ndslice.topology: vmap;

auto x = [1.0, 2, 4, 5, 8, 10, 12, 15, 19, 22].idup.sliced;
auto y = [17.0, 0, 16, 4, 10, 15, 19, 5, 18, 6].idup.sliced;
auto interpolant = pchip!double(x, y);

auto xs = x[0 .. $ - 1] + 0.5;
auto ys = xs.vmap(interpolant);

assert(ys.approxEqual([
    5.333333333333334,
    2.500000000000000,
    10.000000000000000,
    4.288971807628524,
    11.202580845771145,
    16.250000000000000,
    17.962962962962962,
    5.558593750000000,
    17.604662698412699,
    ]));
@safe Spline!(T, N, GridIterators) pchip(SliceKind ykind, yIterator)(GridVectors grid, scope Slice!(ykind, [N], yIterator) values);
Unbounded piecewise spline hermite interpolating polynomial.
Parameters:
points x values for interpolant
Slice!(ykind, [N], yIterator) values f(x) values for interpolant

Constraints: points and values must have the same length >= 3

Returns:
@trusted void pchipSlopes(IG, IV, IS, SliceKind gkind, SliceKind vkind, SliceKind skind)(scope Slice!(gkind, [1], IG) points, scope Slice!(vkind, [1], IV) values, scope Slice!(skind, [1], IS) slopes);
Computes slopes for piecewise spline hermite interpolating polynomial.
Parameters:
Slice!(gkind, [1], IG) points x values for interpolant
Slice!(vkind, [1], IV) values f(x) values for interpolant
Slice!(skind, [1], IS) slopes uninitialized ndslice to write slopes into

Constraints: points, values, and slopes must have the same length >= 3