Problem 4.8

meshfree 2D interpolation with compactly supported RBFs

% setup
f = @(x) 4^2*prod(x.*(1-x),2);
phi = @(S,r) max(spones(S)-r,0).^6.*(35*r.^2+18*r+3*spones(S))/3; % Wendlands \phi_3,2
ep = 30;
tic
% constructing the interpolant
N = 100;
X1 = linspace(0,1,N)'; [XX,YY] = meshgrid(X1,X1); X = [XX(:) YY(:)];
D = sdistm(X,X,1/ep);
D = phi(D+speye(size(D)),ep*D);
y = f(X);
c = D\y;
% evaluating the interpolant
M = 2*N;
X1_e = linspace(1/M,1-1/M,M)'; [XX_e,YY_e] = meshgrid(X1_e,X1_e); X_e = [XX_e(:) YY_e(:)];
D_e = sdistm(X_e,X,1/ep);
D_e = phi(spones(D_e),ep*D_e);
y_e = D_e*c;
toc
nnz(D)/prod(size(D))
% output
surf(XX_e,YY_e,reshape(y_e,M,M)); shading interp; light('Position',[-1 0 0]);
Elapsed time is 2.549467 seconds.
ans =
    0.0036