【问题标题】:How to use BicubicSplineInterpolator in Apache Commons Math?如何在 Apache Commons Math 中使用 BicubicSplineInterpolator?
【发布时间】:2015-01-21 13:45:08
【问题描述】:

我有三个数组 x、y 和 value。 对于每个 x,y , f(x,y) = value;

我不明白如何使用 BicubicSplineInterpolator 类。 我需要找到不同 x 和 y 的值

这是课程的链接 http://commons.apache.org/proper/commons-math/javadocs/api-3.3/org/apache/commons/math3/analysis/interpolation/BicubicSplineInterpolator.html

TIA

【问题讨论】:

    标签: java apache interpolation


    【解决方案1】:

    从文档中,BicubicSplineInterpolator() 要求数据点形成网格状图案。因此,您应该提供一个 x 值数组(长度 = m)和一个 y 值数组(长度 = m)和一个函数值矩阵(长度 = mxn)。

    【讨论】:

      【解决方案2】:

      我同意这些文档非常违反直觉。更糟糕的是,BicubicSplineInterpolator() 有问题,请参阅 https://issues.apache.org/jira/browse/MATH-1166,请使用 http://commons.apache.org/proper/commons-math/changes-report.html 中记录的 BicubicInterpolator。

      插值适用于常规网格(例如 3x3 网格,每个网格点都有一个值)。

      您需要定义网格位置。 (在这个例子中,我们在 x 和 y 维度上都有 0、128、256。但是这些只是数字,您可以在 X 上使用不同范围的温度和湿度。)

      然后用每个网格点的实际值定义一个矩阵,制作一个插值器,该插值器返回一个插值函数,可以计算任意 x,y 处的任意值。

          final double[] xValues = new double[] {0,128,256};
          final double[] yValues = new double[] {0,128,256};
      
          final double[][] fValues = new double[][] {{1, 0, 1},
              {0, 0, 1},
              {0, 0, 1}};
      
              final BivariateGridInterpolator interpolator = new BicubicInterpolator();
              final BivariateFunction function = interpolator.interpolate(xValues, yValues,fValues);
      
              for (int y=0;y<255;y++) {
                  for (int x=0;x<255;x++) {
                      double value=function.value(x,  y);
                      // do something with this
                  }
              }
      

      【讨论】:

        猜你喜欢
        • 2012-04-23
        • 2014-08-06
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-12-12
        • 1970-01-01
        • 2013-02-24
        相关资源
        最近更新 更多