# forum.alglib.net

ALGLIB forum
 It is currently Fri Jul 19, 2024 5:35 am

 All times are UTC

### Forum rules

1. This forum can be used for discussion of both ALGLIB-related and general numerical analysis questions
2. This forum is English-only - postings in other languages will be removed.

 Page 1 of 1 [ 1 post ]
 Print view Previous topic | Next topic
Author Message
 Post subject: spline2d_bicubic examplePosted: Wed Sep 19, 2012 10:12 am

Joined: Wed Sep 19, 2012 9:34 am
Posts: 1
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,

Top

 Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending
 Page 1 of 1 [ 1 post ]

 All times are UTC

#### Who is online

Users browsing this forum: Bing [Bot] and 19 guests

 You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot post attachments in this forum

Search for:
 Jump to:  Select a forum ------------------ ALGLIB forum    ALGLIB-discuss
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group