## Class CubicSplineNakSolver

• java.lang.Object
• com.opengamma.strata.math.impl.interpolation.CubicSplineNakSolver

• public class CubicSplineNakSolver
extends Object
Solves cubic spline problem with Not-A-Knot endpoint conditions, where the third derivative at the endpoints is the same as that of their adjacent points.
• ### Constructor Summary

Constructors
Constructor Description
CubicSplineNakSolver()
• ### Method Summary

All Methods
Modifier and Type Method Description
protected DoubleArray[] combinedMatrixEqnSolver​(double[][] doubMat1, double[] doubVec, double[][] doubMat2)
Cubic spline and its node sensitivity are respectively obtained by solving a linear problem Ax=b where A is a square matrix and x,b are vector and AN=L where N,L are matrices
protected DoubleMatrix[] getCommonCoefficientWithSensitivity​(double[] xValues, double[] yValues, double[] intervals, double[][] toBeInv, double[] commonVector, double[][] commonVecSensitivity)
Cubic spline and its node sensitivity are respectively obtained by solving a linear problem Ax=b where A is a square matrix and x,b are vector and AN=L where N,L are matrices
protected double[][] getCommonMatrixElements​(double[] intervals)
Cubic spline is obtained by solving a linear problem Ax=b where A is a square matrix and x,b are vector
protected DoubleMatrix[] getCommonSensitivityCoeffs​(double[] intervals, double[][] solnMatrix)
protected DoubleMatrix getCommonSplineCoeffs​(double[] xValues, double[] yValues, double[] intervals, double[] solnVector)
protected double[] getCommonVectorElements​(double[] yValues, double[] intervals)
Cubic spline is obtained by solving a linear problem Ax=b where A is a square matrix and x,b are vector
protected double[][] getCommonVectorSensitivity​(double[] intervals)
Node sensitivity is obtained by solving a linear problem AN = L where A,N,L are matrices
protected double[] getDiffs​(double[] xValues)
DoubleArray getKnotsMat1D​(double[] xValues)
protected double[] matrixEqnSolver​(double[][] doubMat, double[] doubVec)
Cubic spline is obtained by solving a linear problem Ax=b where A is a square matrix and x,b are vector This can be done by LU decomposition
DoubleMatrix solve​(double[] xValues, double[] yValues)
One-dimensional cubic spline If (xValues length) = (yValues length), Not-A-Knot endpoint conditions are used If (xValues length) + 2 = (yValues length), Clamped endpoint conditions are used
DoubleMatrix[] solveMultiDim​(double[] xValues, DoubleMatrix yValuesMatrix)
Multi-dimensional cubic spline If (xValues length) = (yValuesMatrix NumberOfColumn), Not-A-Knot endpoint conditions are used If (xValues length) + 2 = (yValuesMatrix NumberOfColumn), Clamped endpoint conditions are used
DoubleMatrix[] solveWithSensitivity​(double[] xValues, double[] yValues)
One-dimensional cubic spline If (xValues length) = (yValues length), Not-A-Knot endpoint conditions are used If (xValues length) + 2 = (yValues length), Clamped endpoint conditions are used
• ### Methods inherited from class java.lang.Object

clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
• ### Constructor Detail

• #### CubicSplineNakSolver

public CubicSplineNakSolver()
• ### Method Detail

• #### solve

public DoubleMatrix solve​(double[] xValues,
double[] yValues)
One-dimensional cubic spline If (xValues length) = (yValues length), Not-A-Knot endpoint conditions are used If (xValues length) + 2 = (yValues length), Clamped endpoint conditions are used
Parameters:
xValues - X values of data
yValues - Y values of data
Returns:
Coefficient matrix whose i-th row vector is (a_0,a_1,...) for i-th intervals, where a_0,a_1,... are coefficients of f(x) = a_0 + a_1 x^1 + .... Note that the degree of polynomial is NOT necessarily 3
• #### solveWithSensitivity

public DoubleMatrix[] solveWithSensitivity​(double[] xValues,
double[] yValues)
One-dimensional cubic spline If (xValues length) = (yValues length), Not-A-Knot endpoint conditions are used If (xValues length) + 2 = (yValues length), Clamped endpoint conditions are used
Parameters:
xValues - X values of data
yValues - Y values of data
Returns:
Array of matrices: the 0-th element is Coefficient Matrix (same as the solve method above), the i-th element is \frac{\partial a^{i-1}_j}{\partial yValues_k} where a_0^i,a_1^i,... are coefficients of f^i(x) = a_0^i + a_1^i (x - xValues_{i}) + .... with x \in [xValues_{i}, xValues_{i+1}]
• #### solveMultiDim

public DoubleMatrix[] solveMultiDim​(double[] xValues,
DoubleMatrix yValuesMatrix)
Multi-dimensional cubic spline If (xValues length) = (yValuesMatrix NumberOfColumn), Not-A-Knot endpoint conditions are used If (xValues length) + 2 = (yValuesMatrix NumberOfColumn), Clamped endpoint conditions are used
Parameters:
xValues - X values of data
yValuesMatrix - Y values of data, where NumberOfRow defines dimension of the spline
Returns:
A set of coefficient matrices whose i-th row vector is (a_0,a_1,...) for the i-th interval, where a_0,a_1,... are coefficients of f(x) = a_0 + a_1 x^1 + .... Each matrix corresponds to an interpolation (xValues, yValuesMatrix RowVector) Note that the degree of polynomial is NOT necessarily 3
• #### getKnotsMat1D

public DoubleArray getKnotsMat1D​(double[] xValues)
Parameters:
xValues - X values of data
Returns:
X values of knots (Note that these are NOT necessarily xValues if nDataPts=2,3)
• #### getDiffs

protected double[] getDiffs​(double[] xValues)
Parameters:
xValues - X values of Data
Returns:
{xValues[1]-xValues[0], xValues[2]-xValues[1],...} xValues (and corresponding yValues) should be sorted before calling this method
• #### getCommonSplineCoeffs

protected DoubleMatrix getCommonSplineCoeffs​(double[] xValues,
double[] yValues,
double[] intervals,
double[] solnVector)
Parameters:
xValues - X values of Data
yValues - Y values of Data
intervals - {xValues[1]-xValues[0], xValues[2]-xValues[1],...}
solnVector - Values of second derivative at knots
Returns:
Coefficient matrix whose i-th row vector is {a_0,a_1,...} for i-th intervals, where a_0,a_1,... are coefficients of f(x) = a_0 + a_1 x^1 + ....
• #### getCommonSensitivityCoeffs

protected DoubleMatrix[] getCommonSensitivityCoeffs​(double[] intervals,
double[][] solnMatrix)
Parameters:
intervals - {xValues[1]-xValues[0], xValues[2]-xValues[1],...}
solnMatrix - Sensitivity of second derivatives (x 0.5)
Returns:
Array of i coefficient matrices \frac{\partial a^i_j}{\partial y_k}
• #### getCommonCoefficientWithSensitivity

protected DoubleMatrix[] getCommonCoefficientWithSensitivity​(double[] xValues,
double[] yValues,
double[] intervals,
double[][] toBeInv,
double[] commonVector,
double[][] commonVecSensitivity)
Cubic spline and its node sensitivity are respectively obtained by solving a linear problem Ax=b where A is a square matrix and x,b are vector and AN=L where N,L are matrices
Parameters:
xValues - X values of data
yValues - Y values of data
intervals - {xValues[1]-xValues[0], xValues[2]-xValues[1],...}
toBeInv - The matrix A
commonVector - The vector b
commonVecSensitivity - The matrix L
Returns:
Coefficient matrices of interpolant (x) and its node sensitivity (N)
• #### getCommonMatrixElements

protected double[][] getCommonMatrixElements​(double[] intervals)
Cubic spline is obtained by solving a linear problem Ax=b where A is a square matrix and x,b are vector
Parameters:
intervals - the intervals
Returns:
Endpoint-independent part of the matrix A
• #### getCommonVectorElements

protected double[] getCommonVectorElements​(double[] yValues,
double[] intervals)
Cubic spline is obtained by solving a linear problem Ax=b where A is a square matrix and x,b are vector
Parameters:
yValues - Y values of Data
intervals - {xValues[1]-xValues[0], xValues[2]-xValues[1],...}
Returns:
Endpoint-independent part of vector b
• #### getCommonVectorSensitivity

protected double[][] getCommonVectorSensitivity​(double[] intervals)
Node sensitivity is obtained by solving a linear problem AN = L where A,N,L are matrices
Parameters:
intervals - {xValues[1]-xValues[0], xValues[2]-xValues[1],...}
Returns:
The matrix L
• #### matrixEqnSolver

protected double[] matrixEqnSolver​(double[][] doubMat,
double[] doubVec)
Cubic spline is obtained by solving a linear problem Ax=b where A is a square matrix and x,b are vector This can be done by LU decomposition
Parameters:
doubMat - Matrix A
doubVec - Vector B
Returns:
Solution to the linear equation, x
• #### combinedMatrixEqnSolver

protected DoubleArray[] combinedMatrixEqnSolver​(double[][] doubMat1,
double[] doubVec,
double[][] doubMat2)
Cubic spline and its node sensitivity are respectively obtained by solving a linear problem Ax=b where A is a square matrix and x,b are vector and AN=L where N,L are matrices
Parameters:
doubMat1 - The matrix A
doubVec - The vector b
doubMat2 - The matrix L
Returns:
The solutions to the linear systems, x,N