%% Bicubic Spline Interpolant to Mexican Hat Function
% Up to rounding errors, and assuming that x is a vector with at least four entries, the statement pp = csapi(x,y) put the same spline into pp as does the statement:
% pp = fn2fm(spapi(augknt(x([1 3:(end-2) end]),4),x,y),'pp');
% except that the description of the spline obtained this second way will not use break at x(2) and x(n-1).
% As a simple bivariate example, plot a bicubic spline interpolant to the Mexican Hat function:

x =.0001+[-4:.2:4]; 
y = -3:.2:3;
[yy,xx] = meshgrid(y,x);
r = pi*sqrt(xx.^2+yy.^2); 
z = sin(r)./r;
bcs = csapi( {x,y}, z ); 
fnplt( bcs ) 
axis([-5 5 -5 5 -.5 1])

% Since MATLAB® considers the entry z(i,j) as the value at (x(j),y(i)), the code reverses x and y in the call to meshgrid. The Curve Fitting Toolbox® instead follows the Approximation Theory standard whereas z(i,j) is the value at (x(i),y(j)).
% For this reason, you have to be cautious when you are plotting values of such a bivariate spline with the aid of the MATLAB mesh function, as shown here:

xf = linspace(x(1),x(end),41); 
yf = linspace(y(1),y(end),41);
mesh(xf, yf, fnval( bcs, {xf, yf}).')

%  Note the use of the transpose of the matrix of values obtained from fnval.
% Copyright 2019 The MathWorks, Inc.