Class PolynomialSplineFunction
- java.lang.Object
-
- org.apache.commons.math3.analysis.polynomials.PolynomialSplineFunction
-
- All Implemented Interfaces:
DifferentiableUnivariateFunction
,UnivariateDifferentiableFunction
,UnivariateFunction
public class PolynomialSplineFunction extends java.lang.Object implements UnivariateDifferentiableFunction, DifferentiableUnivariateFunction
Represents a polynomial spline function.A polynomial spline function consists of a set of interpolating polynomials and an ascending array of domain knot points, determining the intervals over which the spline function is defined by the constituent polynomials. The polynomials are assumed to have been computed to match the values of another function at the knot points. The value consistency constraints are not currently enforced by
PolynomialSplineFunction
itself, but are assumed to hold among the polynomials and knot points passed to the constructor.N.B.: The polynomials in the
polynomials
property must be centered on the knot points to compute the spline function values. See below.The domain of the polynomial spline function is
[smallest knot, largest knot]
. Attempts to evaluate the function at values outside of this range generate IllegalArgumentExceptions.The value of the polynomial spline function for an argument
x
is computed as follows:- The knot array is searched to find the segment to which
x
belongs. Ifx
is less than the smallest knot point or greater than the largest one, anIllegalArgumentException
is thrown. - Let
j
be the index of the largest knot point that is less than or equal tox
. The value returned ispolynomials[j](x - knot[j])
-
-
Field Summary
Fields Modifier and Type Field Description private double[]
knots
Spline segment interval delimiters (knots).private int
n
Number of spline segments.private PolynomialFunction[]
polynomials
The polynomial functions that make up the spline.
-
Constructor Summary
Constructors Constructor Description PolynomialSplineFunction(double[] knots, PolynomialFunction[] polynomials)
Construct a polynomial spline function with the given segment delimiters and interpolating polynomials.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description UnivariateFunction
derivative()
Get the derivative of the polynomial spline function.double[]
getKnots()
Get an array copy of the knot points.int
getN()
Get the number of spline segments.PolynomialFunction[]
getPolynomials()
Get a copy of the interpolating polynomials array.boolean
isValidPoint(double x)
Indicates whether a point is within the interpolation range.PolynomialSplineFunction
polynomialSplineDerivative()
Get the derivative of the polynomial spline function.double
value(double v)
Compute the value for the function.DerivativeStructure
value(DerivativeStructure t)
Simple mathematical function.
-
-
-
Field Detail
-
knots
private final double[] knots
Spline segment interval delimiters (knots). Size is n + 1 for n segments.
-
polynomials
private final PolynomialFunction[] polynomials
The polynomial functions that make up the spline. The first element determines the value of the spline over the first subinterval, the second over the second, etc. Spline function values are determined by evaluating these functions at(x - knot[i])
where i is the knot segment to which x belongs.
-
n
private final int n
Number of spline segments. It is equal to the number of polynomials and to the number of partition points - 1.
-
-
Constructor Detail
-
PolynomialSplineFunction
public PolynomialSplineFunction(double[] knots, PolynomialFunction[] polynomials) throws NullArgumentException, NumberIsTooSmallException, DimensionMismatchException, NonMonotonicSequenceException
Construct a polynomial spline function with the given segment delimiters and interpolating polynomials. The constructor copies both arrays and assigns the copies to the knots and polynomials properties, respectively.- Parameters:
knots
- Spline segment interval delimiters.polynomials
- Polynomial functions that make up the spline.- Throws:
NullArgumentException
- if either of the input arrays isnull
.NumberIsTooSmallException
- if knots has length less than 2.DimensionMismatchException
- ifpolynomials.length != knots.length - 1
.NonMonotonicSequenceException
- if theknots
array is not strictly increasing.
-
-
Method Detail
-
value
public double value(double v)
Compute the value for the function. SeePolynomialSplineFunction
for details on the algorithm for computing the value of the function.- Specified by:
value
in interfaceUnivariateFunction
- Parameters:
v
- Point for which the function value should be computed.- Returns:
- the value.
- Throws:
OutOfRangeException
- ifv
is outside of the domain of the spline function (smaller than the smallest knot point or larger than the largest knot point).
-
derivative
public UnivariateFunction derivative()
Get the derivative of the polynomial spline function.- Specified by:
derivative
in interfaceDifferentiableUnivariateFunction
- Returns:
- the derivative function.
-
polynomialSplineDerivative
public PolynomialSplineFunction polynomialSplineDerivative()
Get the derivative of the polynomial spline function.- Returns:
- the derivative function.
-
value
public DerivativeStructure value(DerivativeStructure t)
Simple mathematical function.UnivariateDifferentiableFunction
classes compute both the value and the first derivative of the function.- Specified by:
value
in interfaceUnivariateDifferentiableFunction
- Parameters:
t
- function input value- Returns:
- function result
- Since:
- 3.1
-
getN
public int getN()
Get the number of spline segments. It is also the number of polynomials and the number of knot points - 1.- Returns:
- the number of spline segments.
-
getPolynomials
public PolynomialFunction[] getPolynomials()
Get a copy of the interpolating polynomials array. It returns a fresh copy of the array. Changes made to the copy will not affect the polynomials property.- Returns:
- the interpolating polynomials.
-
getKnots
public double[] getKnots()
Get an array copy of the knot points. It returns a fresh copy of the array. Changes made to the copy will not affect the knots property.- Returns:
- the knot points.
-
isValidPoint
public boolean isValidPoint(double x)
Indicates whether a point is within the interpolation range.- Parameters:
x
- Point.- Returns:
true
ifx
is a valid point.
-
-