Class Interpolation.InterpolatedFunction
- java.lang.Object
-
- ca.cgjennings.math.Interpolation.InterpolatedFunction
-
- All Implemented Interfaces:
Fn
- Direct Known Subclasses:
Interpolation.CubicSpline
,Interpolation.LinearRegression
,Interpolation.QuadraticRegression
- Enclosing class:
- Interpolation
public abstract static class Interpolation.InterpolatedFunction extends java.lang.Object implements Fn
This is a base class for interpolated functions. An interpolated function is given a set of points. It then creates a function for a curve that passes through or near those points, interpolating "smoothly" between them.One way to think of this is that you have a mystery curve that you don't have a function for, but that you have some (possibly noisy) points which are on or near the curve. An InterpolatedFunction will create a function for your mystery curve, allowing you to evaluate the function for any point instead of just your sample points. Depending on the kind of interpolation, the data may be assumed to be noisy (the interpolator finds a curve of best fit, effectively adjusting the points to fit an idealized curve) or it may assume that the data are perfect (the interpolator passes through each points, adjusting the curve as needed). It may also fall between these extremes, coming close to each point but not necessarily passing through it.
-
-
Constructor Summary
Constructors Constructor Description InterpolatedFunction(double[] x, double[] y)
Creates an interpolated function for the points (x[0],y[0]), (x[1],y[1]), ..., (x[x.length-1],y[y.length-1).
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected void
checkPoints(double[] x, double[] y)
Checks that the set of sample points satisfy any criteria for using the interpolator.abstract double
f(double x)
Returns the y-value of the interpolation function given an x-value.
-
-
-
Constructor Detail
-
InterpolatedFunction
public InterpolatedFunction(double[] x, double[] y)
Creates an interpolated function for the points (x[0],y[0]), (x[1],y[1]), ..., (x[x.length-1],y[y.length-1). The nature of the interpolation is determined by the concrete implementation.The base class calls
checkPoints(double[], double[])
in order to validate the input, but does nothing else.- Parameters:
x
- an array of x-values for the pointsy
- an array of y-values for the points- Throws:
java.lang.NullPointerException
- if either array isnull
java.lang.IllegalArgumentException
- if the data point criteria are not met
-
-
Method Detail
-
checkPoints
protected void checkPoints(double[] x, double[] y)
Checks that the set of sample points satisfy any criteria for using the interpolator. The base class checks the following:- x and y must be non-
null
and have the same length - there must be at least one point (note that the concrete subclass may require more than one point; check the specific class for details)
- the values of x must be strictly increasing (for all j in 1 to x.length-1, x[j-1] < x[j]); this simply means that the x values must be sorted from lowest to highest and must not contain any repeats
- Parameters:
x
- an array of x-values for the pointsy
- an array of y-values for the points- Throws:
java.lang.NullPointerException
- if either array isnull
java.lang.IllegalArgumentException
- if the criteria above are not met
- x and y must be non-
-
-