Skip to content

Akima.Function.createAkimaSplineInterpolator

Christian d'Heureuse edited this page Sep 25, 2026 · 1 revision

commons-math-interpolation / Akima / createAkimaSplineInterpolator

Function: createAkimaSplineInterpolator()

function createAkimaSplineInterpolator(xVals, yVals): UniFunction;

Defined in: Akima.ts:46

Returns a cubic spline interpolating function for a dataset, using the Akima algorithm.

The Akima spline is a piecewise cubic Hermite spline. The first derivative at each interior knot point is determined locally from the slopes of the neighboring segments, which reduces the overshooting that other cubic splines show near outliers and abrupt changes. Only the first derivative is continuous at the knot points. The first derivatives at the first two and the last two knot points are computed by fitting a parabola through the first three or the last three points.

For n interpolation points with x values x[0] < x[1] < ... < x[n-1] (the "knot points"), the spline function consists of n - 1 cubic polynomials, one for each segment x[i] ... x[i+1]. The Akima algorithm requires that n >= 5.

Arguments outside the range of the knot points are extrapolated with the cubic polynomial of the first or last segment. If the argument is NaN, the function returns NaN.

The passed arrays are not referenced by the returned function.

The Akima algorithm was originally formulated by Hiroshi Akima in his 1970 paper "A New Method of Interpolation and Smooth Curve Fitting Based on Local Procedures", J. ACM 17, 4 (October 1970), 589-602, DOI 10.1145/321607.321609.

This implementation is a port of the AkimaSplineInterpolator class of Apache Commons Math, which is based on the method CubicSpline.InterpolateAkimaSorted of the Math.NET Numerics library.

Parameters

xVals

ArrayLike<number>

The arguments of the interpolation points, in strictly increasing order. The values must be finite.

yVals

ArrayLike<number>

The values of the interpolation points.

Returns

UniFunction

A function which interpolates the dataset.

Throws

Error If xVals and yVals have different lengths, if there are fewer than 5 points, or if xVals contains non-finite values or is not strictly increasing.

Clone this wiki locally