cubicSpline

Syntax

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

Arguments

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.

Details

Cubic spline data interpolator.

Return value: A dictionary with two keys:

  • c: Coefficients of the polynomials on each segment.

  • x: Breakpoints. The input x.

Examples

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

// output
c->[-0.041850075616506,-0.261272044545537,1.144593104969939,0,-0.041850075616507,-0.386822271395055,0.496498789029347,0.841470984807897,0.146891060089045,-0.512372498244576,-0.402695980610284,0.909297426825682,0.160544611441946,-0.071699317977441,-0.986767796832301,0.141120008059867,0.036476302757735,0.409934516348399,-0.648532598461344,-0.756802495307928,-0.120619990666048,0.519363424621603,0.280765342508658,-0.958924274663138,-0.178733575459463,0.157503452623459,0.957632219753719,-0.279415498198926,-0.025369476962727,-0.378697273754929,0.736438398622249,0.656986598718789,-0.025369476962726,-0.454805704643109,-0.09706457977579,0.989358246623382]
x->[0,1,2,3,4,5,6,7,8,9]

Related Function: cubicSplinePredict