外推 OutOfRangeException Apache Commons Math

Extrapolation OutOfRangeException Apache Commons Math

我正在尝试使用 Apache Commons 数学库和 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 是否有任何方法可以使用此方法进行外推?我该如何解决这个错误。

如果您查看文档 PolynomialSimlineFunction Doucumentaition,您可以阅读值方法 "OutOfRangeException - if v is outside of the domain of the spline function (smaller than the smallest knot point or larger than the largest knot point)."

这是非常合理的,因为结外的插值不是您的函数的近似值。从数学上讲,您的尝试根本没有意义。