Package com.xinapse.numerical
Class CubicSplineInterpolator
java.lang.Object
com.xinapse.numerical.AbstractInterpolator
com.xinapse.numerical.CubicSplineInterpolator
- All Implemented Interfaces:
Serializable
public class CubicSplineInterpolator
extends com.xinapse.numerical.AbstractInterpolator
implements Serializable
A cubic spline interpolator for tabulated values of (x,y).
- See Also:
-
Constructor Summary
ModifierConstructorDescriptionprotected
CubicSplineInterpolator
(double[] x, double[] y) Create a newCubicSplineInterpolator
interpolator, from arrays of tabulated x and y values. -
Method Summary
Modifier and TypeMethodDescriptiondouble
getFirstDeriv
(double xPt) Returns the first derivative of the function value at a given value of x.double
getSecondDeriv
(double xPt) Returns the second derivative of the function value at a given value of x.double[]
Returns the internal array of second derivatives values at the knots.double
interpolate
(double xPt) Returns an interpolated value of y for a value of x.static CubicSplineInterpolator
newInstance
(double[] x, double[] y) Create a newCubicSplineInterpolator
interpolator, from arrays of tabulated x and y values.static CubicSplineInterpolator
newInstance
(double[] x, float[] y) Create a newCubicSplineInterpolator
interpolator, from arrays of tabulated x and y values.static CubicSplineInterpolator
newInstance
(float[] x, float[] y) Create a newCubicSplineInterpolator
interpolator, from arrays of tabulated x and y values.void
setEndDerivs
(double dydx1, double dydxn) Set the first derivative values of theCubicSplineInterpolator
at the end points of the abscissa range, overriding a natural spline.Methods inherited from class com.xinapse.numerical.AbstractInterpolator
getLimits, orderPoints
-
Constructor Details
-
CubicSplineInterpolator
Create a newCubicSplineInterpolator
interpolator, from arrays of tabulated x and y values. The values in the two arrays are copied, and therefore the arrays can be reused.- Parameters:
x
- the array of x-values.y
- the array of y-values.- Throws:
InvalidArgumentException
- if the x- and y arrays are of different lengths.
-
-
Method Details
-
newInstance
public static CubicSplineInterpolator newInstance(float[] x, float[] y) throws InvalidArgumentException Create a newCubicSplineInterpolator
interpolator, from arrays of tabulated x and y values. The values in the two arrays are copied, and therefore the arrays can be reused.- Parameters:
x
- the array of x-values.y
- the array of y-values.- Returns:
- a new
CubicSplineInterpolator
interpolator. - Throws:
InvalidArgumentException
- if the x- and y arrays are of different lengths.
-
newInstance
public static CubicSplineInterpolator newInstance(double[] x, float[] y) throws InvalidArgumentException Create a newCubicSplineInterpolator
interpolator, from arrays of tabulated x and y values. The values in the two arrays are copied, and therefore the arrays can be reused.- Parameters:
x
- the array of x-values.y
- the array of y-values.- Returns:
- a new
CubicSplineInterpolator
interpolator. - Throws:
InvalidArgumentException
- if the x- and y arrays are of different lengths.
-
newInstance
public static CubicSplineInterpolator newInstance(double[] x, double[] y) throws InvalidArgumentException Create a newCubicSplineInterpolator
interpolator, from arrays of tabulated x and y values. The values in the two arrays are copied, and therefore the arrays can be reused.- Parameters:
x
- the array of x-values.y
- the array of y-values.- Returns:
- a new
CubicSplineInterpolator
interpolator. - Throws:
InvalidArgumentException
- if the x- and y arrays are of different lengths.
-
setEndDerivs
public void setEndDerivs(double dydx1, double dydxn) Set the first derivative values of theCubicSplineInterpolator
at the end points of the abscissa range, overriding a natural spline.- Parameters:
dydx1
- the first derivative value at the left-hand end of the abscissa range.dydxn
- the first derivative value at the right-hand end of the abscissa range.
-
getSecondDerivs
public double[] getSecondDerivs()Returns the internal array of second derivatives values at the knots.- Returns:
- the internal array of second derivatives values.
-
interpolate
public double interpolate(double xPt) Returns an interpolated value of y for a value of x. If the x-value lies outside the range of the tabulated values, linear extrapolation is used.- Specified by:
interpolate
in classcom.xinapse.numerical.AbstractInterpolator
- Parameters:
xPt
- the x value for which to return the interpolated y-value.- Returns:
- the interpolated value of y for a value of x.
-
getFirstDeriv
public double getFirstDeriv(double xPt) Returns the first derivative of the function value at a given value of x.- Parameters:
xPt
- the x value for which to return the first derivative value.- Returns:
- the first derivative of the function value at a given value of x.
-
getSecondDeriv
public double getSecondDeriv(double xPt) Returns the second derivative of the function value at a given value of x.- Parameters:
xPt
- the x value for which to return the second derivative value.- Returns:
- the second derivative of the function value at a given value of x.
-