I'm trying to implement an Extrapolation function using the Apache Commons Math lib and the PolynomialSplineFunction & LinearInterpolator functions.
public double[] linearInterp(double[] x, double[] y, double[] xi) {
LinearInterpolator li = new LinearInterpolator(); // or other interpolator
PolynomialSplineFunction psf = li.interpolate(x, y);
double[] yi = new double[xi.length];
for (int i = 0; i < xi.length; i++) {
yi[i] = psf.value(xi[i]);
}
return yi;
}
x = [0, 60, 120,180,240];
y = [196, 232, 250, 157, 300];
xi = [300, 360, 420];
the problem is that if I use a value outside of the range of x
I get a OutOfRangeException
is there any way to Extrapolate using this method? how do I get around this error.