CubicSpline Module

Cubic splines interpolate two dimensional data by applying piecewise cubic polynomials that are continuous at the input coordinates (knots). The function itself, the first- and second derivative are continuous at the knots.

Types and nested modules

Type/Module Description

Hermite

Hermite cubic splines are defined by the function values and their slopes (first derivatives). If the slopws are unknown, they must be estimated.

BoundaryCondition

CubicSplineCoef

Contains x data, y data (c0), slopes (c1), curvatures (c2), and the third derivative at each knot

Functions and values

Function or value Description

getFirstDerivative coefficients x

Full Usage: getFirstDerivative coefficients x

Parameters:
    coefficients : CubicSplineCoef - Interpolation functions coefficients.
    x : float - X value of which the slope should be predicted.

Returns: float Function that takes an x value and returns the function slope.

Returns function that takes x value and predicts the corresponding slope.

x values outside of the xValue range are predicted by straight lines defined by the nearest knot!

coefficients : CubicSplineCoef

Interpolation functions coefficients.

x : float

X value of which the slope should be predicted.

Returns: float

Function that takes an x value and returns the function slope.

Example

 
 // e.g. days since a certain event
 let xData = vector [|0.;1.;5.;4.;3.;|]
 // some measured feature
 let yData = vector [|1.;5.;4.;13.;17.|]
 
 // get coefficients for piecewise interpolating cubic polynomials
 let coefficients = 
     CubicSpline.interpolate CubicSpline.BoundaryConditions.Natural xData yData

 // get slope function
 let func = CubicSpline.getFirstDerivative(coefLinSpl)

 // get slope at x=3.4
 func 3.4

getSecondDerivative coefficients x

Full Usage: getSecondDerivative coefficients x

Parameters:
    coefficients : CubicSplineCoef - Interpolation functions coefficients.
    x : float - X value of which the curvature should be predicted.

Returns: float Function that takes an x value and returns the function curvature.

Returns function that takes x value and predicts the corresponding curvature.

x values outside of the xValue range are predicted by straight lines defined by the nearest knot!

coefficients : CubicSplineCoef

Interpolation functions coefficients.

x : float

X value of which the curvature should be predicted.

Returns: float

Function that takes an x value and returns the function curvature.

Example

 
 // e.g. days since a certain event
 let xData = vector [|0.;1.;5.;4.;3.;|]
 // some measured feature
 let yData = vector [|1.;5.;4.;13.;17.|]
 
 // get coefficients for piecewise interpolating cubic polynomials
 let coefficients = 
     CubicSpline.interpolate CubicSpline.BoundaryConditions.Natural xData yData

 // get curvature function
 let func = CubicSpline.getSecondDerivative(coefLinSpl)

 // get curvature at x=3.4
 func 3.4

getThirdDerivative coefficients x

Full Usage: getThirdDerivative coefficients x

Parameters:
    coefficients : CubicSplineCoef - Interpolation functions coefficients.
    x : float - X value of which the y value should be predicted.

Returns: float Function that takes an x value and returns the function third derivative.

Returns function that takes x value and predicts the corresponding third derivative.

x values outside of the xValue range are predicted by straight lines defined by the nearest knot!

coefficients : CubicSplineCoef

Interpolation functions coefficients.

x : float

X value of which the y value should be predicted.

Returns: float

Function that takes an x value and returns the function third derivative.

Example

 
 // e.g. days since a certain event
 let xData = vector [|0.;1.;5.;4.;3.;|]
 // some measured feature
 let yData = vector [|1.;5.;4.;13.;17.|]
 
 // get coefficients for piecewise interpolating cubic polynomials
 let coefficients = 
     CubicSpline.interpolate CubicSpline.BoundaryConditions.Natural xData yData

 // get third derivative function
 let func = CubicSpline.getThirdDerivative(coefLinSpl)

 // get third derivative at x=3.4
 func 3.4

interpolate boundaryCondition xValues yValues

Full Usage: interpolate boundaryCondition xValues yValues

Parameters:
    boundaryCondition : BoundaryCondition - Condition that defines how slopes and curvatures are defined at the left- and rightmost knot
    xValues : Vector<float> - Note: Must not contain duplicate x values (use Approximation.regularizeValues to preprocess data!)
    yValues : Vector<float> - function value at x values

Returns: CubicSplineCoef Coefficients that define the interpolating function.

Computes coefficients for piecewise interpolating splines. In the form of [a0;b0;c0;d0;a1;b1;...;d(n-2)]. where: fn(x) = (an)x^3+(bn)x^2+(cn)x+(dn)

boundaryCondition : BoundaryCondition

Condition that defines how slopes and curvatures are defined at the left- and rightmost knot

xValues : Vector<float>

Note: Must not contain duplicate x values (use Approximation.regularizeValues to preprocess data!)

yValues : Vector<float>

function value at x values

Returns: CubicSplineCoef

Coefficients that define the interpolating function.

Example

 
 // e.g. days since a certain event
 let xData = vector [|0.;1.;5.;4.;3.;|]
 // some measured feature
 let yData = vector [|1.;5.;4.;13.;17.|]

 // get coefficients for piecewise interpolating cubic polynomials
 let coefficients = 
     CubicSpline.interpolate CubicSpline.BoundaryConditions.Natural xData yData

interpolateWithCurvature x y curvatures

Full Usage: interpolateWithCurvature x y curvatures

Parameters:
Returns: CubicSplineCoef

Interpolates x and y coordinates with given slopes at the knots. Probably makes no sense because slope isnt continuous anymore

x : vector
y : vector
curvatures : vector
Returns: CubicSplineCoef

interpolateWithSlopes x y slopes

Full Usage: interpolateWithSlopes x y slopes

Parameters:
Returns: CubicSplineCoef

Interpolates x and y coordinates with given slopes at the knots. Curvature cannot be set anymore

x : vector
y : vector
slopes : vector
Returns: CubicSplineCoef

predict coefficients x

Full Usage: predict coefficients x

Parameters:
    coefficients : CubicSplineCoef - Interpolation functions coefficients.
    x : float - X value of which the y value should be predicted.

Returns: float Function that takes an x value and returns function value.

Returns function that takes x value and predicts the corresponding interpolating y value.

x values outside of the xValue range are predicted by straight lines defined by the nearest knot!

coefficients : CubicSplineCoef

Interpolation functions coefficients.

x : float

X value of which the y value should be predicted.

Returns: float

Function that takes an x value and returns function value.

Example

 
 // e.g. days since a certain event
 let xData = vector [|0.;1.;5.;4.;3.;|]
 // some measured feature
 let yData = vector [|1.;5.;4.;13.;17.|]
 
 // get coefficients for piecewise interpolating cubic polynomials
 let coefficients = 
     CubicSpline.interpolate CubicSpline.BoundaryConditions.Natural xData yData

 // get interpolating function 
 let func = CubicSpline.predict(coefLinSpl)

 // get function value at x=3.4
 func 3.4

predictWithinRange coefficients x

Full Usage: predictWithinRange coefficients x

Parameters:
    coefficients : CubicSplineCoef - Interpolation functions coefficients.
    x : float - X value of which the y value should be predicted.

Returns: float Function that takes an x value and returns function value.

Returns function that takes x value (that lies within the range of input x values) and predicts the corresponding interpolating y value.

Only defined within the range of the given xValues!

coefficients : CubicSplineCoef

Interpolation functions coefficients.

x : float

X value of which the y value should be predicted.

Returns: float

Function that takes an x value and returns function value.

Example

 
 // e.g. days since a certain event
 let xData = vector [|0.;1.;5.;4.;3.;|]
 // some measured feature
 let yData = vector [|1.;5.;4.;13.;17.|]
 
 // get coefficients for piecewise interpolating cubic polynomials
 let coefficients = 
     CubicSpline.interpolate CubicSpline.BoundaryConditions.Natural xData yData

 // get interpolating value
 let func = CubicSpline.predictWithinRange(coefLinSpl)

 // get function value at x=3.4
 func 3.4