我正在尝试使用 Apache Commons Math 库和 PolynomialSplineFunction 和 LinearInterpolator 函数来实现外推函数。
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];
问题是,如果我使用的值超出了x
我得到的范围,OutOfRangeException
有没有办法使用这种方法进行推断?我该如何解决这个错误。