Class BaseInterpolator
java.lang.Object
com.irurueta.numerical.interpolation.BaseInterpolator
- Direct Known Subclasses:
BarycentricRationalInterpolator
,CubicSplineInterpolator
,LinearInterpolator
,PolynomialInterpolator
,RationalInterpolator
Abstract base class used by all interpolation implementations.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected int
private final int
private int
protected final int
Length of data to be taken into account on x's and y's.protected final int
Length of x and y values to be interpolated.protected final double[]
X values to be used for interpolation estimation.protected final double[]
Y values to be used for interpolation estimation. -
Constructor Summary
ConstructorsConstructorDescriptionBaseInterpolator
(double[] x, double[] y, int m) Constructor.BaseInterpolator
(double[] x, double[] y, int m, boolean check) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionprotected int
hunt
(double x) Given a value x, returns a value j such that x is (insofar as possible) centered in the subrange xx[j..j+mm-1], where xx is the stored array.double
interpolate
(double x) protected int
locate
(double x) Given a value x, returns a value j such that x is (insofar as possible) centered in the subrange xx[j..j+mm-1], where xx is the stored array.abstract double
rawinterp
(int jlo, double x) Actual interpolation method to be implemented by subclasses.
-
Field Details
-
n
protected final int nLength of x and y values to be interpolated. -
mm
protected final int mmLength of data to be taken into account on x's and y's. -
cor
protected int cor -
jsav
private int jsav -
dj
private final int dj -
xx
protected final double[] xxX values to be used for interpolation estimation. Must be monotonic (either increasing or decreasing). -
yy
protected final double[] yyY values to be used for interpolation estimation.
-
-
Constructor Details
-
BaseInterpolator
BaseInterpolator(double[] x, double[] y, int m, boolean check) Constructor.- Parameters:
x
- x values to interpolate to. Values in x must be monotonic (either increasing or decreasing)y
- y values to interpolate to.m
- length of x's and y's to take into account. Must be less or equal than x or y length.check
- true to make validations, false otherwise.- Throws:
IllegalArgumentException
- if x or y have invalid length or m exceeds length of x or y.
-
BaseInterpolator
BaseInterpolator(double[] x, double[] y, int m) Constructor.- Parameters:
x
- x values to interpolate to. Values in x must be monotonic (either increasing or decreasing)y
- y values to interpolate to.m
- length of x's and y's to take into account. Must be less or equal than x or y length.- Throws:
IllegalArgumentException
- if x or y have invalid length or m exceeds length of x or y.
-
-
Method Details
-
interpolate
- Parameters:
x
- value to obtain interpolation for.- Returns:
- interpolated value.
- Throws:
InterpolationException
- if interpolation fails.
-
rawinterp
Actual interpolation method to be implemented by subclasses.- Parameters:
jlo
- index where value x to be interpolated in located in the array of xx.x
- value to obtain interpolation for.- Returns:
- interpolated value.
- Throws:
InterpolationException
- if interpolation fails.
-
locate
protected int locate(double x) Given a value x, returns a value j such that x is (insofar as possible) centered in the subrange xx[j..j+mm-1], where xx is the stored array. The value in xx must be monotonic, either increasing or decreasing. The returned value is not less than 0, nor greater than n - 1.- Parameters:
x
- value to obtain interpolation for.- Returns:
- position where value to obtain interpolation lies in the array of
xx
.
-
hunt
protected int hunt(double x) Given a value x, returns a value j such that x is (insofar as possible) centered in the subrange xx[j..j+mm-1], where xx is the stored array. The value in xx must be monotonic, either increasing or decreasing. The returned value is not less than 0, nor greater than n - 1. This method starts with a guessed position in the table. It first "hunts" either up or own, in increments of 1, then 2, then 3, etc. until the desired value is bracketed. It then bisects in the bracketed interval. At worst, this routine is about a factor of 2 slower thanlocate(double)
(if the hunt phase expands to include the whole table). At best, it can be a factor of log(n)/log(2) faster thanlocate(double)
if the desired point is usually quite close to the input guess.- Parameters:
x
- value to obtain interpolation for.- Returns:
- position where value to obtain interpolation lies in the array of
xx
.
-