commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Adam Bedrossian <abedross...@applieddefense.com>
Subject [math] Problem with the BicubicSplineInterpolator?
Date Thu, 10 Jul 2014 18:20:52 GMT
I have encountered a use case with the BicubicSplineInterpolator where the
interpolated values that are being returned seem incorrect.  Furthermore,
the values do not match those generated by MatLab using the interp2 'cubic'
method.

Here is a snippet of code that uses the interpolator:

double[] xValues = new double[] {36, 36.001, 36.002};
        double[] yValues = new double[] {-108.00, -107.999, -107.998};

        double[][] fValues = new double[][] {{1915, 1906, 1931},
                                        {1877, 1889, 1894},
                                        {1878, 1873, 1888}};

        BicubicSplineInterpolator interpolator = new
BicubicSplineInterpolator();
        BicubicSplineInterpolatingFunction interpolatorFunction =
interpolator.interpolate(xValues, yValues, fValues);

        double[][] results = new double[9][9];
        double x = 36;
        int arrayIndexX = 0, arrayIndexY = 0;

        while(x <= 36.002) {
            double y = -108;
            arrayIndexY = 0;
            while (y <= -107.998) {
                results[arrayIndexX][arrayIndexY] =
interpolatorFunction.value(x,  y);
                System.out.println(results[arrayIndexX][arrayIndexY]);
                y = y + 0.00025;
                arrayIndexY++;
            }

            x = x + 0.00025;
            arrayIndexX++;
        }

If we focus just on the interpolated value at x = 36 and y = -107.99975
(the second iteration of the loop), the value = -3938.593749982256.
Compared to MatLab, the value is 1901.8438.

I've also posted this scenario on Stack Overflow which can be found here:
http://stackoverflow.com/questions/24618336/apache-commons-math-bicubicsplineinterpolator-is-returning-strange-interpolated

Am I using the interpolator incorrectly?  Is this something I should bug?

Thank you
Adam

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message