title: Bilinear interpolation in Matlab (without built in functions)
body: <p>I'm having some trouble understanding how to code the bilinear interpolation in Matlab. Our assignment has us using this function;</p>
  
  <p>B(x,y) = z_(ij) + a*(x - xj) + b*(y - yi) + c*(x - xj)(y - yi)</p>
  
  <p>We're building 2 functions, one that calculates the coefficients (Which i've done already and it passed the 'check' algorithm from the professor) and another function that computes the function. below is the code I have.
  We're given, x,y,z,xi, and yi, while a,b,c have already been computed.</p>
  
  <p><strong>My issue:</strong> The function runs but returns a matrix when it should only return a vector. However, it does return the correct values in column 1, rows 1 &amp; 2 which is really confusing me. Also, the values we're given are a square matrix (z) and 1x2 x and y values, however, in the second part of the problem we're givene an z = m x n matrix that is not a square matrix so my code isn't working for that. Below is my current code. Any help would be appreciated but i don't expect you to just give me the answer!</p>
  
  <pre><code>%Given x = [0,1], y=[0,1], z=[0,1;2,4], a = 1, b = 2, c = 1, xi = [0,.5],      yi = [0,.5]
  
  function zi = bilinear_eval(x, y, z, a, b, c, xi, yi )
      [m,n] = size(z);
      for j = 1:length(xi)
          for i = length(x)
          zi(i,j) = z(j,j) + a*(xi(i) - x(j)) + b*(yi(i) - y(j)) + c*(xi(i) - x(j))*(yi(i) - y(j))
          end
      end
      end
  </code></pre>