Skip to content

Utils.Function.evaluatePolySegment

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

commons-math-interpolation / Utils / evaluatePolySegment

Function: evaluatePolySegment()

function evaluatePolySegment(
   xVals, 
   segmentCoeffs, 
   x
): number;

Defined in: Utils.ts:53

Evaluates a piecewise polynomial function (e.g. a spline) at the specified argument value.

The segment is selected by the position of x within the knots xVals: segment i is used for xVals[i] <= x < xVals[i + 1]. Arguments below xVals[0] are evaluated with the first segment and arguments at or above the start of the last segment are evaluated with the last segment (extrapolation).

Parameters

xVals

ArrayLike<number>

The x values of the knots, in strictly increasing order. xVals[i] is the start point of segment i. Normally it contains one element more than segmentCoeffs (the end point of the last segment).

segmentCoeffs

ArrayLike<number>[]

The polynomial coefficients of the segments, in ascending order (constant term first). The polynomials are relative to the segment start, i.e. segment i is evaluated as a polynomial of x - xVals[i]. Must contain at least one segment.

x

number

The argument value.

Returns

number

The value of the piecewise polynomial function at x, or NaN if x is NaN.

Clone this wiki locally