Contents Previous Next Subchapters Current Chapters-> interp interp1 lagrange polyfit smospl cubespl cubeval interp2 mlmode_interp2 snewton brent linlsq linlsqb nlsq dnlsq nlsqbox dnlsqb conjdir neldermead conjgrad minline lemke Qpos Qbox Qpro sqp relative fordiff cendiff autodiff testder testgrad testhess Parent Chapters-> Omatrix6 fit interp2 Search Tools-> contents reference index search

Two Dimensional Piecewise Bilinear Interpolation
 Syntax `interp2(`z`, `xz`, `yz`, `xi`, `yi`)` See Also mlmode_interp2 , interp , smospl

Description
Returns the values of the piecewise bilinear interpolant that has the value `z(i,j)` at the point `(xz(i), yz(j))` for `i = 1` to the row dimension of xz and `j = 1` to the column dimension of yz. The (i,j)-th element of the return value is the value of the interpolant at `(xi(i), yi(j))` for `i = 1` to the row dimension of xi and `j = 1` to the column dimension of yi. The return value has the same type as z, the same row dimension as xi, and the same column dimension as yi. Both the row and column dimensions of z must be greater than 1. The column vector xz has the same number of rows as z. The row vector yz has the same number of columns as z. ``` ```The vectors xz, yz, xi, and yi are real or double-precision. In addition the vectors xz, and yz, are strictly monotone increasing or decreasing. If z is complex, the return value is complex. If all the arguments are real, the return value is real. Otherwise, the return value is double-precision.

Example
The example below uses `interp2` to interpolate the function `x y` between 1 and 5 in both the `x` and `y` directions. The interpolation exactly matches the function because `x y` is bilinear. ```      xz = {1., 5.}      yz = [1., 5.]      z  = xz * yz      xi = {1., 2., 3., 4., 5.}      yi = xi'      interp2(z, xz, yz, xi, yi) ``` returns ```      {      [ 1 , 2 , 3 , 4 , 5 ]      [ 2 , 4 , 6 , 8 , 10 ]      [ 3 , 6 , 9 , 12 , 15 ]      [ 4 , 8 , 12 , 16 , 20 ]      [ 5 , 10 , 15 , 20 , 25 ]      } ```
Reference
A function `f(x,y)` is bilinear if its second partial derivative with respect to `x` and its second partial derivative with respect to `y` is zero. The interpolating function is continuous and it is bilinear over rectangles of the form ```      {(x,y) : xz  < x  < xz   and  yz  < y  < yz   }                 i          i+1       i          i+1 ```