I observed a strange thing in using the class. If the length of X-vector supplied to the operator() is >= Y-vector length ,it gives proper z-values at all the points. However, I get wrong z-values are obtained at some points if X-Vector length < Y_vector length, and those points seem to be related to the difference between the two vector lengths.
eg., In the following code,I assign z-value=1 at all the nodes in the 5X6 grid.All points should give an interpolated z-value of 1 from this function. But there are some points which have a random value .It works OK if I make it 6X5.
Am I using it wrongly, or could there possibly be some problem?
Regards,
Amar
Following is the code:
{
std::vector<double> x(5); x[0]=0; x[1]=1; x[2]=2; x[3]=3; x[4]=4; //x[5]=5; std::vector<double> y(6); y[0]=0; y[1]=1; y[2]=2; y[3]=3; y[4]=4; y[5]=5; Math::Matrix z(x.size(),y.size()); int i,j; std::vector<MyExcelRange::StringVectorType> matrix; for(i=0;i<x.size();i++) { for(j=0;j<y.size();j++) { z[i][j]= 1; } } ofstream myfile("outfile2.txt");
myfile << "************************** before " << endl; for(i=0;i<x.size();i++) for(j=0;j<y.size();j++) myfile << "x = " << x[i] << " y = " << y[j] << " z = " << z[i][j] << endl; myfile << "************************** from interpolation" << endl; for(i=0;i<x.size();i++) for(j=0;j<y.size();j++) myfile << "x = " << x[i] << " y = " << y[j] << " z = " << Math::BicubicSplineInterpolation<std::vector<double>::const_iterator,std::vector<double>::const_iterator,Math::Matrix> (x.begin(),x.end(),y.begin(),y.end(),z)(x[i],y[j]) << endl; } Following is the output:
************************** before
x = 0 y = 0 z = 1 x = 0 y = 1 z = 1 x = 0 y = 2 z = 1 x = 0 y = 3 z = 1 x = 0 y = 4 z = 1 x = 0 y = 5 z = 1 x = 1 y = 0 z = 1 x = 1 y = 1 z = 1 x = 1 y = 2 z = 1 x = 1 y = 3 z = 1 x = 1 y = 4 z = 1 x = 1 y = 5 z = 1 x = 2 y = 0 z = 1 x = 2 y = 1 z = 1 x = 2 y = 2 z = 1 x = 2 y = 3 z = 1 x = 2 y = 4 z = 1 x = 2 y = 5 z = 1 x = 3 y = 0 z = 1 x = 3 y = 1 z = 1 x = 3 y = 2 z = 1 x = 3 y = 3 z = 1 x = 3 y = 4 z = 1 x = 3 y = 5 z = 1 x = 4 y = 0 z = 1 x = 4 y = 1 z = 1 x = 4 y = 2 z = 1 x = 4 y = 3 z = 1 x = 4 y = 4 z = 1 x = 4 y = 5 z = 1 "************************** from interpolation x = 0 y = 0 z = 1 x = 0 y = 1 z = 1 x = 0 y = 2 z = 1 x = 0 y = 3 z = 1 x = 0 y = 4 z = 1 x = 0 y = 5 z = -1.45682e+144 x = 1 y = 0 z = 1 x = 1 y = 1 z = 1 x = 1 y = 2 z = 1 x = 1 y = 3 z = 1 x = 1 y = 4 z = 1 x = 1 y = 5 z = -1.45682e+144 x = 2 y = 0 z = 1 x = 2 y = 1 z = 1 x = 2 y = 2 z = 1 x = 2 y = 3 z = 1 x = 2 y = 4 z = 1 x = 2 y = 5 z = -1.45682e+144 x = 3 y = 0 z = 1 x = 3 y = 1 z = 1 x = 3 y = 2 z = 1 x = 3 y = 3 z = 1 x = 3 y = 4 z = 1 x = 3 y = 5 z = -1.45682e+144 x = 4 y = 0 z = 1 x = 4 y = 1 z = 1 x = 4 y = 2 z = 1 x = 4 y = 3 z = 1 x = 4 y = 4 z = 1 x = 4 y = 5 z = -1.45682e+144 Do you Yahoo!? The New Yahoo! Shopping - with improved product search |
At 12:41 AM 10/14/03, amar singh wrote:
>I observed a strange thing in using the class. >Am I using it wrongly, or could there possibly be some problem? > >Following is the code: > { > std::vector<double> x(5); > ... > std::vector<double> y(6); > ... > Math::Matrix z(x.size(),y.size()); Amar, we'll have to document it better. When I wrote it, I visualized the thing as on two Carthesian axes: [yM] [ ] |. | | | |. | | Z matrix | |. | | | |y2| | | [y1] [ | [ x1 x2 . . . xN ] Therefore, the i-th y-value corresponds to the i-th row, and the j-th x-value to the j-th column. The constructor of Matrix being: Matrix(Size rows, Size columns); the constructor call in your code should be: Matrix(y.size(), x.size()) Please, if anyone feels it's the wrong way around, just tell me so that we can change the parameter order... Later, Luigi |
Ligui,
Thank you very much for your help, and sorry for creating the confusion.
It does work perfect, only I was not aware .
Thanks,
At 12:41 AM 10/14/03, amar singh wrote: Do you Yahoo!? The New Yahoo! Shopping - with improved product search |
Luigi,
I have a minor suggestion, which could prevent mistakes and hard to track bugs in using the matrix - It should throw an error for out of range access.
I think it would be helpful in avoiding mistakes in use.eg., If the matrix element accesses a pointer outside its allocation range, it could be quite upredictable and very hard to debug.
BTW, your 'state of the art' Matrix class looks really excellent!
Regards,
Amar
amar singh <[hidden email]> wrote:
Do you Yahoo!? The New Yahoo! Shopping - with improved product search |
Free forum by Nabble | Edit this page |