0

I have an array[160,160] with 27 measured datapoints and want to interpolate the whole array. I have found the following code, but don't get it which parameters I have to hand over so that this method works:

 public static double BilinearInterpolation(double[] x, double[] y, double[,] z, double xval, double yval)
            {
                //calculates single point bilinear interpolation
                double zval = 0.0;
                for (int i = 0; i < x.Length - 1; i++)
                {
                    for (int j = 0; j < y.Length - 1; j++)
                    {   
                        if(xval>=x[i] && xval<x[i+1] && yval>=y[j] && yval<y[j+1])
                        {
                        zval = z[i,j]*(x[i+1]-xval)*(y[j+1]-yval)/(x[i+1]-x[i])/(y[j+1]-y[j])+
                               z[i+1,j]*(xval-x[i])*(y[j+1]-yval)/(x[i+1]-x[i])/(y[j+1]-y[j])+
                               z[i,j+1]*(x[i+1]-xval)*(yval-y[j])/(x[i+1]-x[i])/(y[j+1]-y[j])+
                               z[i+1,j+1]*(xval-x[i])*(yval-y[j])/(x[i+1]-x[i])/(y[j+1]-y[j]);
                        }
                    }
                }
                return zval;
            }

           public static double[] BilinearInterpolation(double [] x, double[] y, double[,]z,double[] xvals, double[]yvals)
           {
               //calculates multiple point bilinear interpolation
               double[] zvals = new double[xvals.Length];
               for (int i = 0; i < xvals.Length; i++)
                   zvals[i] = BilinearInterpolation(x, y, z, xvals[i], yvals[i]);
               return zvals;
           }

double[] x --> the x koordinates of my points in an array?

double[] y --> the y koordinates of my points in an array?

double[,] z --> an array, where the interpolated values get stored?

double xval --> ??

double yval --> ??

is this correct? or maybe you have a easier way to interpolate the array bilinear.

user3498536
  • 23
  • 1
  • 5
  • 1
    Did the place you found the code have an explanation? – Sayse May 15 '14 at 06:50
  • http://de.slideshare.net/martinalonso72/numerical-methodsalgorithmsandtoolsinc i have it from here! (page 231-233) There is an axplanation, but I don't get it :( – user3498536 May 15 '14 at 07:28
  • Take a look at [one of my previous posts](http://stackoverflow.com/questions/22151994/2d-array-interpolation/22153181#22153181) which can be directly used for 2D arrays. – Nico Schertler May 15 '14 at 07:30
  • @NicoSchertler: i even don't get your code. what is integerX, integerY, fractionX and fractiony exactly? – user3498536 May 15 '14 at 08:09
  • They are what the comments say: The integer and fraction part of the x and y coordinate. – Nico Schertler May 15 '14 at 08:32

1 Answers1

0

Looks to me like xval and yval are the values at which you want to interpolate. These are the coordinates of the point that you want evaluated.

Ben
  • 3,241
  • 4
  • 35
  • 49