Problem 1.5

basic meshfree 2d interpolation with euclidean distance basis functions

Contents

(a) interpolation

% constructing the interpolant
s = 2;
f = @(x) 4^s*prod(x.*(1-x),2);
N = 10;
%X1d = linspace(0,1,N)'; [XX,YY] = meshgrid(X1d,X1d); X = [XX(:) YY(:)];
X = rand(N^2,2);
y = f(X);
D = distm(X,X);
c = D\y;
% evaluating it
M = 30;
X1d_e = linspace(0,1,M)'; [XX_e,YY_e] = meshgrid(X1d_e,X1d_e); X_e = [XX_e(:) YY_e(:)];
D_e = distm(X_e,X);
y_e = D_e*c;
% plotting it
surf(XX_e,YY_e,reshape(y_e,M,M)); shading interp

error in dependence of N

M = 50;
X1d_e = linspace(0,1,M)'; [XX_e,YY_e] = meshgrid(X1d_e,X1d_e); X_e = [XX_e(:) YY_e(:)];
N = logspace(1,1.6,20);
for k = 1:20,
    X1d = linspace(0,1,N(k))'; [XX,YY] = meshgrid(X1d,X1d); X = [XX(:) YY(:)];
    % X = rand(round(N(k))^2,2);
    y = f(X);
    D = distm(X,X);
    c = D\y;
    y_e = distm(X_e,X)*c;
    err_2(k) = norm(y_e-f(X_e))/sqrt(M);
    err_inf(k) = norm(y_e-f(X_e),inf);
end
clf; loglog(N,err_2,'o-',N,err_inf,'ro-');
xlabel('N'); ylabel('errors'); legend('L^2-error','L_\infty-error')