MA 5324 Problem 1.3

basic meshfree interpolation with euclidean distance basis functions

Contents

distm.m

function D = distm(X,Y)
% DISTM   Distance matrix.
%  DISTM(X,Y) is the matrix of pairwise euclidean
%  distances between the points in the rows of X and Y
%  code by Paritosh Mokhasi and Gregory Fasshauer
[M,s] = size(X); [N,s] = size(Y);
D = repmat(sum(X.*X,2),1,N) - 2*X*Y' + repmat((sum(Y.*Y,2))',M,1);
D = sqrt(D);

interpolation

% constructing the interpolant
f = @(x) 4*x.*(1-x);
N = 7;
X = linspace(0,1,N)';
y = f(X);
D = distm(X,X);
c = D\y;
% evaluating it
M = 51;
Xt = linspace(0,1,M)';
Dt = distm(Xt,X);
yt = Dt*c;
% plotting the function and its interpolant
plot(X,0,'bo',Xt,f(Xt)); hold on
plot(Xt,yt,'r.-'); xlabel('x'); ylabel('$f,P_f$')
% error estimate
err_2 = norm(yt-f(Xt))/sqrt(M)
err_inf = norm(yt-f(Xt),inf)
err_2 =

    0.0201


err_inf =

    0.0277