Confusion in using BicubicSplineInterpolation

Posted by amar singh on
URL: http://quantlib.414.s1.nabble.com/Confusion-in-using-BicubicSplineInterpolation-tp2714.html

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