Report a bug
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

Authors:
Ilya Yaroshenko
public import mir.interpolate.spline : `Spline`;
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 mir.math.common: approxEqual;
import mir.algorithm.iteration: all;
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;

() @trusted {
auto ys = xs.vmap(interpolant);

assert(ys.all!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`(yIterator, SliceKind ykind)(GridVectors `grid`, Slice!(yIterator, N, ykind) `values`);
Unbounded piecewise spline hermite interpolating polynomial.
Parameters:
 GridVectors `grid` x values for interpolant Slice!(yIterator, N, ykind) `values` f(x) values for interpolant

Constraints `grid` and `values` must have the same length >= 3

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

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