# MA 5324 Problem 2.13

basic meshfree interpolation with other RBFs

## comparison between euclidean distance, Gaussians and inverse multiquadrics

f = @(x) 4*x.*(1-x);
phi = @(ep,r) exp(-(ep*r).^2); ep = 10;             % Gaussian
beta = 1; imqr = @(ep,r) (1+(ep*r).^2).^(-beta);    % inverse multiquadric
ell = 4; trpf = @(ep,r) max(1-(ep*r).^2,0).^ell;    % truncated power function
M = 1000;
X_eval = linspace(0,1,M)';
N = logspace(1,2.8,30);
for k=1:30,
X = linspace(0,1,N(k))';
y = f(X);
D1 = distm(X,X); c1 = D1\y;
D2 = phi(ep,D1); c2 = D2\y;
D3 = imqr(ep,D1); c3 = D3\y;
D4 = trpf(ep,D1); c4 = D4\y;
D_eval1 = distm(X_eval,X);
D_eval2 = phi(ep,D_eval1);
D_eval3 = imqr(ep,D_eval1);
D_eval4 = trpf(ep,D_eval1);
y_eval = f(X_eval);
err_1(k) = norm(D_eval1*c1 - y_eval)/sqrt(M);
err_2(k) = norm(D_eval2*c2 - y_eval)/sqrt(M);
err_3(k) = norm(D_eval3*c3 - y_eval)/sqrt(M);
err_4(k) = norm(D_eval4*c4 - y_eval)/sqrt(M);
end
clf; loglog(N,err_1,'o-',N,err_2,'ro-',N,err_3,'mo-',N,err_4,'ko-');
xlabel('N'); ylabel('errors'); axis tight
legend('euclidean distance','Gaussians','inv. multiquadric ($\beta = 1$)','truncated power function (l = 4)')