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

accuracy of spline2dcalc
http://forum.alglib.net/viewtopic.php?f=2&t=437
Page 1 of 1

Author:  thomashawaii [ Fri Sep 09, 2011 5:06 am ]
Post subject:  accuracy of spline2dcalc

Hi All,

The following code is try to test how the bicubic interpolation and bilinear interpolation behave for some specific function form. With such a high density as 1000X1000, these two interpolation method will not generate much different results. Node [51][49] has the f value as 0.502708. When I use the spline2dcalc function to calculate the same grid. It generate a slightly different answer 0.497108. According to the standard cubic spline algorithm,it is not supposed to happen. May I ask why does this difference take place?

BTW, with the grids density as 100X100 the same thing happens.

Thanks ahead.



#include "ap.h"
#include <iostream>
#include <math.h>
using namespace alglib;
using namespace std;
#include "interpolation.h"
int main()
{
alglib::real_1d_array x;
alglib::real_1d_array y;
alglib::real_2d_array z;
x.setlength(1000);
y.setlength(1000);
z.setlength(1000,1000);
for (int i=0;i<1000;i++)
{
x[i]=0.01*i;
for (int j=0;j<1000;j++)
{
y[j]=0.01*j;
z[i][j]=pow(x[i],0.64)*pow(y[j],0.36);
}
}

spline2dinterpolant s;
spline2dinterpolant p;
spline2dbuildbicubic(x,y,z,1000,1000,s);
spline2dbuildbilinear(x,y,z,1000,1000,p);

cout<<z[51][49]<<endl;
cout<< spline2dcalc(p,0.51,0.49)<<endl;
cout<< pow(0.51,0.64)*pow(0.49,0.36)<<endl;\
cout<< spline2dcalc(p,0.51,0.49)/(pow(0.51,0.64)*pow(0.49,0.36))<<endl;
return 0;
}

Author:  Sergey.Bochkanov [ Fri Sep 09, 2011 9:03 am ]
Post subject:  Re: accuracy of spline2dcalc

That's because z[51][49] corresponds to (x,y)=(0.49,0.51) instead of (0.51,0.49). Different order of variables.

I understand that it can be misleading, but the problem is that there are exist people which prefer both of them. So no matter what I choose, there always will be unsatisfied users :(

Author:  thomashawaii [ Fri Sep 09, 2011 8:51 pm ]
Post subject:  Re: accuracy of spline2dcalc

Thanks a lot, Sergey. It works now.

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