forum.alglib.net

ALGLIB forum
It is currently Sun Dec 22, 2024 1:58 pm

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.



Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: accuracy of spline2dcalc
PostPosted: Fri Sep 09, 2011 5:06 am 
Offline

Joined: Fri Sep 09, 2011 4:46 am
Posts: 2
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;
}


Top
 Profile  
 
 Post subject: Re: accuracy of spline2dcalc
PostPosted: Fri Sep 09, 2011 9:03 am 
Offline
Site Admin

Joined: Fri May 07, 2010 7:06 am
Posts: 927
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 :(


Top
 Profile  
 
 Post subject: Re: accuracy of spline2dcalc
PostPosted: Fri Sep 09, 2011 8:51 pm 
Offline

Joined: Fri Sep 09, 2011 4:46 am
Posts: 2
Thanks a lot, Sergey. It works now.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 30 guests


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

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group