cubicSpline(x, y, bc_type="not-a-knot")


x is a numeric vector containing values of the independent variable. The length of x must be no smaller than 3. Its values must be real and in strictly increasing order.

y is a numeric vector containing values of the dependent variable. The length of y must match the length of x.

bc_type is of STRING type, which can be a scalar, pair, or a vector of length no greater than 2. It specifies the boundary condition type.

  • If bc_type is a string or a vector of length 1, the specified condition will be applied at both ends of a spline.

  • If bc_type is a pair or a vector of length 2, the first and the second value will be applied at the curve start and end respectively.

Its value can be:

  • "not-a-knot" (default): The first and second segment at a curve end are the same polynomial.

  • "clamped": The first derivative at curves ends are zero.

  • "natural": The second derivative at curve ends are zero.


Cubic spline data interpolator.

Return value: A dictionary with two keys:

  • c: Coefficients of the polynomials on each segment.

  • x: Breakpoints. The input x.


n = 10
x = 0..(n-1)
y = sin(x)
model = cubicSpline(x, y, bc_type="not-a-knot")

// output

Related Function: cubicSplinePredict