forum.alglib.net
http://forum.alglib.net/

spline2d_bicubic example
http://forum.alglib.net/viewtopic.php?f=2&t=616
Page 1 of 1

Author:  caduqued [ Wed Sep 19, 2012 10:12 am ]
Post subject:  spline2d_bicubic example

Hi All,

I am implementing a function which uses 2D interpolation. I am using spline2dbuildbicubicv. Regarding the example for the spline2d_bicubic interpolation presented in the reference manual, I suggest a little change. The values presented in the manual/website (as example of results obtained for the given case) are in fact those which are obtained using spline2dbuildbicubicv. However, a simple and quick look at the function [ f(x,y)=x^2+2*y^2 ], shows that the "expected" result for the function is far from correct (a huge error is obtained for the point), whereas but for the derivatives the results presented are OK. This could be misleading as to the applicability / suitability of the function. I reckon there were valid reasons to give an example which intentionally produces a wrong interpolation result. However, I reckon this example could be improved by adding just some few additional grid points, and then the results calculated by the interpolation function are almost exactly to those expected from the analytical solution. I suggest to incorporate a more accurate example, like the one I show below, to indicate the power of the spline2dbuildbicubicv routine.

Code:
    //  Example
    //
    // We use bilinear spline to interpolate f(x,y)=x^2+2*y^2 sampled
    // at (x,y) from [0.0, 0.5, 1.0,2.25] X [0.0, 1.0, 1.2].
    //
    real_1d_array x = "[0.0, 0.5, 1.0, 2.25]";
    real_1d_array y = "[0.0, 1.0, 1.2]";
    real_1d_array f =
        "[0.00,0.25,1.00,5.0625,2.00,2.25,3.00,7.0625,2.88,3.13,3.88,7.9425]";
    spline2dinterpolant ss;
    // build spline
    spline2dbuildbicubicv(x, 4, y, 3, f, 1, ss);

    double vx, vy, v, dx, dy, dxy;
    // calculate S(0.25,0.50)
    vx = 0.25;
    vy = 0.50;
    v = spline2dcalc(ss, vx, vy);
    printf("%.4f\n", double(v)); // EXPECTED: 0.5625

    // calculate derivatives
    spline2ddiff(ss, vx, vy, v, dx, dy, dxy);
    printf("%.4f\n", double(v)); // EXPECTED: 0.5625
    printf("%.4f\n", double(dx)); // EXPECTED: 0.5000
    printf("%.4f\n", double(dy)); // EXPECTED: 2.0000
       
    // calculate S(0.35,0.84)
    vx = 0.35;
    vy = 0.84;
    v = spline2dcalc(ss, vx, vy);
    printf("%.4f\n", double(v)); // EXPECTED: 1.5337

    // calculate derivatives
    spline2ddiff(ss, vx, vy, v, dx, dy, dxy);
    printf("%.4f\n", double(v)); // EXPECTED: 1.5337
    printf("%.4f\n", double(dx)); // EXPECTED: 0.7000
    printf("%.4f\n", double(dy)); // EXPECTED: 3.3600




In any case, I also want to say a big thank you to the ALGLIB code developers for their superb job.

Cheers,

Page 1 of 1 All times are UTC
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/