# MA 5324 Problem 3.5

meshfree interpolation with compactly supported RBFs

## Gaussian and Wendland RBFs

f = @(x) 4*x.*(1-x);
phi = @(r) exp(-r.^2); ep = 1;                  % Gaussian
wld30 = @(r) max(1-r,0).^2;                     % Wendlands \phi_3,0
wld31 = @(r) max(1-r,0).^4.*(4*r+1);            % Wendlands \phi_3,1
wld32 = @(r) max(1-r,0).^6.*(35*r.^2+18*r+3)/3; % Wendlands \phi_3,2
wld33 = @(r) max(1-r,0).^8.*(32*r.^3+25*r.^2+8*r+1); % Wendlands \phi_3,3
x = linspace(0,2,100);
plot(x,phi(3*x),'-',x,wld30(x),'r-',x,wld31(x),'m-',x,wld32(x),'k-',x,wld33(x),'g-');
xlabel('x'); ylabel('$\phi$');
legend('Gaussians','Wendland 3,0','Wendland 3,1','Wendland 3,2','Wendland 3,3')


## comparison

M = 2000;
X_eval = linspace(1/M,1-1/M,M)';
N = logspace(1,3,30);
for k=1:30,
X = linspace(0,1,N(k))';
y = f(X);
D = distm(X,X);
D1 = phi(3*ep*D); c1 = D1\y;
D2 = wld30(ep*D); c2 = D2\y;
D3 = wld31(ep*D); c3 = D3\y;
D4 = wld32(ep*D); c4 = D4\y;
D5 = wld33(ep*D); c5 = D5\y;
D_e = distm(X_eval,X);
D_e1 = phi(3*ep*D_e);
D_e2 = wld30(ep*D_e);
D_e3 = wld31(ep*D_e);
D_e4 = wld32(ep*D_e);
D_e5 = wld33(ep*D_e);
y_eval = f(X_eval);
err_1(k) = norm(D_e1*c1 - y_eval)/sqrt(M); cond1(k) = condest(D1);
err_2(k) = norm(D_e2*c2 - y_eval)/sqrt(M); cond2(k) = condest(D2);
err_3(k) = norm(D_e3*c3 - y_eval)/sqrt(M); cond3(k) = condest(D3);
err_4(k) = norm(D_e4*c4 - y_eval)/sqrt(M); cond4(k) = condest(D4);
err_5(k) = norm(D_e5*c5 - y_eval)/sqrt(M); cond5(k) = condest(D5);
end
clf; loglog(N,err_1,'o-',N,err_2,'ro-',N,err_3,'mo-',N,err_4,'ko-',N,err_5,'go-');
xlabel('N'); ylabel('errors');
legend('Gaussians','Wendland 3,0','Wendland 3,1','Wendland 3,2','Wendland 3,3')
figure
loglog(N,cond1,'o-',N,cond2,'ro-',N,cond3,'mo-',N,cond4,'ko-',N,cond5,'go-');
xlabel('N'); ylabel('condition');
legend('Gaussians','Wendland 3,0','Wendland 3,1','Wendland 3,2','Wendland 3,3')

Warning: Matrix is close to singular or badly scaled. Results may be inaccurate.
RCOND =  5.958000e-17.
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate.
RCOND =  2.221404e-18.
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate.
RCOND =  6.185843e-19.
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate.
RCOND =  3.190797e-18.
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate.
RCOND =  2.023364e-18.
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate.
RCOND =  7.133868e-19.
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate.
RCOND =  2.455242e-19.
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate.
RCOND =  9.275384e-20.
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate.
RCOND =  3.080676e-19.
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate.
RCOND =  1.931010e-19.
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate.
RCOND =  2.448096e-19.
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate.
RCOND =  6.283346e-20.
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate.
RCOND =  7.416121e-21.
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate.
RCOND =  5.828091e-20.
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate.
RCOND =  7.910901e-20.
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate.
RCOND =  8.562753e-22.
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate.
RCOND =  1.953432e-20.
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate.
RCOND =  1.696139e-20.
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate.
RCOND =  5.833147e-17.
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate.
RCOND =  9.311016e-21.
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate.
RCOND =  1.622140e-18.
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate.
RCOND =  6.832683e-21.
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate.
RCOND =  5.939881e-20.
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate.
RCOND =  1.898286e-21.
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate.
RCOND =  7.968473e-21.
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate.
RCOND =  1.219546e-21.
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate.
RCOND =  4.051594e-20.
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate.
RCOND =  6.000479e-22.
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate.
RCOND =  4.682842e-21.
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate.
RCOND =  1.981899e-22.
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate.
RCOND =  9.006931e-21.
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate.
RCOND =  5.891385e-22.
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate.
RCOND =  3.260824e-22.
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate.
RCOND =  2.517645e-21.
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate.
RCOND =  8.892712e-17.
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate.
RCOND =  1.275824e-20.