%Function that approximates a two-dimensional function f(x1,x2)at two
%points in the support of x1 and x2.  It requires the user to input four
%neighboring points x1i,x2j,x1i1, and x2j1 so that x1i<=x1<x1i1 and
%x2i<=x2<x2i1 where the function is approximated at points x1 and x2.  It
%also requires the user to supply the function f(x1,x2).  Written by Philip
%Shaw, Fordham University, 2020.

function[fx1x2]=bilinear(fun,x1i,x1i1,x2j,x2j1,x1,x2)
fx1ix2j=fun([x1i x2j]);
fx1i1x2j=fun([x1i1 x2j]);
fx1ix2j1=fun([x1i x2j1]);
fx1i1x2j1=fun([x1i1 x2j1]);
t=((x1-x1i)/(x1i1-x1i));
u=((x2-x2j)/(x2j1-x2j));
fx1x2=(1-t)*(1-u)*fx1ix2j+t*(1-u)*fx1i1x2j+t*u*fx1i1x2j1+(1-t)*u*fx1ix2j1;  
