Package com.imsl.math
Class Spline
java.lang.Object
com.imsl.math.Spline
- All Implemented Interfaces:
Serializable,Cloneable
- Direct Known Subclasses:
CsAkima,CsInterpolate,CsPeriodic,CsShape,CsSmooth,CsSmoothC2,CsTCB
Spline represents and evaluates univariate piecewise polynomial splines.
A univariate piecewise polynomial (function) p(x) is specified by giving its breakpoint sequence \(\xi \in {\bf R}^n\), the order k (degree k-1) of its polynomial pieces, and the \(k \times (n-1)\) matrix c of its local polynomial coefficients. In terms of this information, the piecewise polynomial (ppoly) function is given by $$ p(x) = \sum_{j=1}^k c_{ji} \frac{(x-\xi_i)^{j-1}}{(j-1)!} \;\;{\rm for}\; \xi_i \le x \le \xi_{i+1} $$ The breakpoint sequence \(\xi\) is assumed to be strictly increasing, and we extend the ppoly function to the entire real axis by extrapolation from the first and last intervals.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected double[]The breakpoint array of length n, where n is the number of piecewise polynomials.protected double[][]Coefficients of the piecewise polynomials.protected static final doubleThe largest relative spacing for double. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidcopyAndSortData(double[] xData, double[] yData) Copy and sort xData into breakPoint and yData into the first column of coef.protected voidcopyAndSortData(double[] xData, double[] yData, double[] weight) Copy and sort xData into breakPoint and yData into the first column of coef.doublederivative(double x) Returns the value of the first derivative of the spline at a point.double[]derivative(double[] x, int ideriv) Returns the value of the derivative of the spline at each point of an array.doublederivative(double x, int ideriv) Returns the value of the derivative of the spline at a point.double[]Returns a copy of the breakpoints.doubleintegral(double a, double b) Returns the value of an integral of the spline.doublevalue(double x) Returns the value of the spline at a point.double[]value(double[] x) Returns the value of the spline at each point of an array.
-
Field Details
-
coef
protected double[][] coefCoefficients of the piecewise polynomials. This is an n by k array, where n is the number of piecewise polynomials and k is the order (degree+1) of the piecewise polynomials.coef[i]contains the coefficients for the piecewise polynomial valid in the interval [x[k],x[k+1]). -
breakPoint
protected double[] breakPointThe breakpoint array of length n, where n is the number of piecewise polynomials. -
EPSILON_LARGE
protected static final double EPSILON_LARGEThe largest relative spacing for double.- See Also:
-
-
Constructor Details
-
Spline
public Spline()
-
-
Method Details
-
copyAndSortData
protected void copyAndSortData(double[] xData, double[] yData) Copy and sort xData into breakPoint and yData into the first column of coef. -
copyAndSortData
protected void copyAndSortData(double[] xData, double[] yData, double[] weight) Copy and sort xData into breakPoint and yData into the first column of coef. -
value
public double value(double x) Returns the value of the spline at a point.- Parameters:
x- adouble, the point at which the spline is to be evaluated- Returns:
- a
doublegiving the value of the spline at the point x
-
derivative
public double derivative(double x) Returns the value of the first derivative of the spline at a point.- Parameters:
x- adouble, the point at which the derivative is to be evaluated- Returns:
- a
doublecontaining the value of the first derivative of the spline at the point x
-
derivative
public double derivative(double x, int ideriv) Returns the value of the derivative of the spline at a point.- Parameters:
x- adouble, the point at which the derivative is to be evaluatedideriv- anintspecifying the derivative to be computed. If zero, the function value is returned. If one, the first derivative is returned, etc.- Returns:
- a
doublecontaining the value of the derivative of the spline at the point x
-
value
public double[] value(double[] x) Returns the value of the spline at each point of an array.- Parameters:
x- adoublearray of points at which the spline is to be evaluated- Returns:
- a
doublearray containing the value of the spline at each point of the array x
-
derivative
public double[] derivative(double[] x, int ideriv) Returns the value of the derivative of the spline at each point of an array.- Parameters:
x- adoublearray of points at which the derivative is to be evaluatedideriv- anintspecifying the derivative to be computed. If zero, the function value is returned. If one, the first derivative is returned, etc.- Returns:
- a
doublearray containing the value of the derivative of the spline at each point of the array x
-
getBreakpoints
public double[] getBreakpoints()Returns a copy of the breakpoints.- Returns:
- a
doublearray containing a copy of the breakpoints
-
integral
public double integral(double a, double b) Returns the value of an integral of the spline.- Parameters:
a- adoublespecifying the lower limit of integrationb- adoublespecifying the upper limit of integration- Returns:
- a
double, the integral of the spline from a to b
-