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; }
|