Constructs multivariate generic interpolant with nodes on rectilinear grid.
Multivariate generic interpolant with nodes on rectilinear grid.
import mir.ndslice; import mir.math.common: approxEqual; struct PieceInterpolant { int value; this()(int value) { this.value = value; } int opCall(uint derivative : 0, X)(int x0, int x1, X x) const { return value; } enum uint derivativeOrder = 0; } alias S = PieceInterpolant; static immutable x = [0, 1, 2, 3]; // can be also an array of floating point numbers static immutable y = [S(10), S(20), S(30)]; auto interpolant = generic(x.rcslice, y.rcslice!(const S)); assert(interpolant(-1) == 10); assert(interpolant(0) == 10); assert(interpolant(0.5) == 10); assert(interpolant(1) == 20); assert(interpolant(1.5) == 20); assert(interpolant(2) == 30); assert(interpolant(3) == 30); assert(interpolant(3.4) == 30); assert(interpolant(3) == 30); assert(interpolant(4) == 30);
2020 Ilia Ki, Kaleidic Associates Advisory Limited, Symmetry Investments
Generic Piecewise Interpolant