MA 5324 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;
X1dt = linspace(0,1,M)'; [XXt,YYt] = meshgrid(X1dt,X1dt); Xt = [XXt(:) YYt(:)];
Dt = distm(Xt,X);
yt = Dt*c;
% plotting it
surf(XXt,YYt,reshape(yt,M,M)); shading interp

error in dependence of N

M = 200;clf
X1dt = linspace(0,1,M)'; [XXt,YYt] = meshgrid(X1dt,X1dt); Xt = [XXt(:) YYt(:)];
N = logspace(1,1.6,20);
for k = 1:20,
    tic;
    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;
    yt = distm(Xt,X)*c;
    err_2(k) = norm(yt-f(Xt))/sqrt(M);
    err_inf(k) = norm(yt-f(Xt),inf);
    cnd(k) = condest(D);
    t(k) = toc;
end
h = 1./N.^2;
subplot(221); loglog(h,err_2,'o-'); axis([min(h) max(h) 5e-3 1e-1])
xlabel('h'); ylabel('$L^2$-error')
subplot(222); loglog(h,err_inf,'ro-'); axis([min(h) max(h) 1e-3 3e-2])
xlabel('h'); ylabel('$L^\infty$-error');
subplot(223); semilogx(N,cnd,'x-');
xlabel('N'); ylabel('cond(D)');
subplot(224); semilogx(N,t,'xr-');
xlabel('N'); ylabel('cpu time [s]');