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

splinebuild2cubic
http://forum.alglib.net/viewtopic.php?f=2&t=351
Page 1 of 1

Author:  estevan [ Mon Apr 25, 2011 10:49 pm ]
Post subject:  splinebuild2cubic

Hi,

I'm getting this message when I call spline2dbuildcubic:

terminate called after throwing an instance of 'alglib::ap_error'
Aborted

Here is the code:
==========================================
using namespace alglib;


int main(){

ae_int_t w = 2;

real_1d_array a = "[0,1]";

real_1d_array b = "[0,1]";

real_2d_array f = "[2.2,3.3,1.1,4.4]";

spline2dinterpolant s;

spline2dbuildbicubic(a,b,f,w,w,s);

return 0;
}
==============================================
The error msg didn't give me enough to go on so any ideas on what I'm doing wrong would be great.

Thanks much,
Estevan

Author:  Sergey.Bochkanov [ Tue Apr 26, 2011 4:30 am ]
Post subject:  Re: splinebuild2cubic

F must be 2-dimensional array, "[[2.2,3.3],[1.1,4.4]]", for example.

Author:  estevan [ Tue Apr 26, 2011 3:29 pm ]
Post subject:  Re: splinebuild2cubic

Thanks Sergey. Got past my error. Greatly appreciate it.

Author:  estevan [ Tue Apr 26, 2011 4:50 pm ]
Post subject:  Re: splinebuild2cubic

One other thing --

when I go to a non-square array it's throwing alglib::ap_error again.

it throws it at the real_2d_array declaration.

Code:
int main(){
double value;
ae_int_t m = 2;
ae_int_t n = 3;
real_1d_array x = "[0,1,2]";
real_1d_array y = "[0,1]";
real_2d_array f = "[[1,2],[1,2,3]]";
spline2dinterpolant s;
spline2dbuildbicubic(x,y,f,m,n,s);
value = spline2dcalc(s,.5,.5);
printf("value=%f\n",value);
return 0;
}


it's a 2 row x 3 col array and I can't see what the problem is. any ideas would be great.

thanks.

Author:  Sergey_Bikovsky [ Tue Apr 26, 2011 7:40 pm ]
Post subject:  Re: splinebuild2cubic

Hi. I have a litle problem with my code
(Qt 4.7.0 with MinGW and Qt creator.)
Code:
int main(int argc, char *argv[])
{
    QCoreApplication proga(argc, argv);

alglib::ae_int_t  max_x, max_y;
alglib::spline2dinterpolant c;

    max_x=15;
    max_y=15;


XX.setlength(max_x);
YY.setlength(max_y);
FF.setlength(max_y, max_x);

for (int i=0; i<max_x-1; i++)
{
    XX[i]=1.0*i;
}

for (int j=0; j<max_y-1; j++)
{
    YY[j]=1.0+j;
}

for (int i=0; i<max_x-1; i++)
for (int j=0; j<max_y-1; j++)
{
    FF[j][i]=YY[j]*XX[i];
}
/**********************************************/
spline2dbuildbicubic(XX, YY, FF, max_x, max_y, &c);
/**********************************************/
return proga.exec();
}

My compiler tells me about error in line between stars.
it tells, that "no mathcing functions for call to "splie2dbicubic(alglib::real_1d_array&, alglib::real_1d_array&, alglib::real_2d_array&, alglib::ae_int_t&, alglib::ae_int_t&, alglib_impl::spline2dinterpolant*)

Where is my error?
I am sorry for my non-excelent C++

Author:  Sergey.Bochkanov [ Wed Apr 27, 2011 4:41 pm ]
Post subject:  Re: splinebuild2cubic

2estevan: "[[1,2],[1,2,3]]" is a non-rectangular array, you have to add one more element to the first row.

Author:  Sergey.Bochkanov [ Wed Apr 27, 2011 4:43 pm ]
Post subject:  Re: splinebuild2cubic

2Sergey_Bikovsky: you should remove & from last parameter, i.e. it should be "spline2dbuildbicubic(XX, YY, FF, max_x, max_y, c)"

Author:  Sergey_Bikovsky [ Wed Apr 27, 2011 4:53 pm ]
Post subject:  Re: splinebuild2cubic

Thanks.
It Works now :)

Author:  estevan [ Wed Apr 27, 2011 5:33 pm ]
Post subject:  Re: splinebuild2cubic

Thanks Sergey - I realized this about 30mins ago as I drew it out on a plot. tested with a function field that is 2 by 3 and with one that is 3 by 2. Just wanted to be ready for any dimension as I will be using this for wind fields.

--estevan

Author:  emscheffel [ Sat Jan 11, 2014 1:08 pm ]
Post subject:  Re: splinebuild2cubic

Hi there,

I have a similar problem as some of the people who have already submitted code snippets. This is my code:

Code:
void interpn(double *outgrid, double *gridx, double *gridy, double *gridxy, double *agrid1, double *agrid2, int ngrid, int ngrid2) {
alglib::real_1d_array gridxx;
gridxx.setcontent(ngrid,gridx);

alglib::real_1d_array gridyy;
gridyy.setcontent(ngrid2,gridy);

alglib::real_1d_array ingrid;
ingrid.setcontent(ngrid*ngrid2,gridxy);

alglib::spline1dinterpolant splone;

// build spline
alglib::spline2dbuildbicubicv(gridxx,ngrid,gridyy,ngrid2,ingrid,1,splone);

for (int ii=0; ii<ngrid; ii++) {
    for (int jj=0; jj<ngrid2; jj++) {
        for (int kk=0; kk<nstates_as; kk++){
            for (int ll=0; ll<nstates_is; ll++){
                outgrid[ii*ngrid2+jj+(kk+ll)*(ngrid*ngrid2)] = alglib::spline2dcalc(splone, agrid1[ii*ngrid2+jj], agrid2[ii*ngrid2+jj]);
           }
        }
    }
}

}
.
.
.
interpn(&k2prime_bu[0][0][0][0],kkgrid,kmgrid,tempmat,&kprime[0][0][0][0],&kmprime[0][0][0][0],ngrid,ngrid2);



Most but not all of the arrays I pass to the function are from the C++ Boost library's multidimensional array library. Running this code gives me the dreaded
terminate called after throwing an instance of 'alglib::ap_error'. I know that the error is thrown at the point where the spline is build, i.e. at the point

Code:
alglib::spline2dbuildbicubicv(gridxx,ngrid,gridyy,ngrid2,ingrid,1,splone);


Any suggestions where I may be making a mistake here?

Thanks,
Eric

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