# Problem 1.7

basic meshfree interpolation with Gaussian RBFs

## Contents

## (a) interpolation

% constructing the interpolant f = @(x) 4*x.*(1-x); phi = @(ep,r) exp(-(ep*r).^2); ep = 1; N = 5; X = linspace(0,1,N)'; y = f(X); D = phi(ep, distm(X,X)); c = D\y; % evaluating it M = 50; X_eval = linspace(0,1,M)'; D_eval = phi(ep,distm(X_eval,X)); y_eval = D_eval*c; % plotting the function and its interpolant clf; plot(X,0,'bo',X_eval,f(X_eval)); hold on plot(X_eval,y_eval,'rx-'); xlabel('x'); ylabel('f,P_f')

## (b) comparison with euclidean basis functions

ep = 12; M = 1000; X_eval = linspace(0,1,M)'; N = logspace(1,2.8,20); for k=1:20, X = linspace(0,1,N(k))'; y = f(X); D1 = distm(X,X); c1 = D1\y; D2 = phi(ep,distm(X,X)); c2 = D2\y; D_eval1 = distm(X_eval,X); D_eval2 = phi(ep,distm(X_eval,X)); err_1(k) = norm(D_eval1*c1 - f(X_eval))/sqrt(M); err_2(k) = norm(D_eval2*c2 - f(X_eval))/sqrt(M); end clf; loglog(N,err_1,'o-',N,err_2,'ro-'); xlabel('N'); ylabel('errors'); legend('euclidean distance RBFs','Gaussian RBFs')

Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 3.474898e-17. Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 1.407670e-17. Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 5.075618e-19. Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 2.028118e-19. Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 8.507393e-19. Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 3.709260e-20. Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 1.202834e-19. Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 4.077956e-20. Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 3.166924e-20. Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 2.474070e-20. Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 6.424456e-20. Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 4.611902e-20.

## (c) error of Gaussian RBF interpolant in dependence of the shape parameter

N = 2^5; X = linspace(0,1,N)'; Dp = distm(X,X); y = f(X); X_eval = linspace(0,1,200)'; Dp_eval = distm(X_eval,X); ep = logspace(-1,1.4,40); for k = 1:40, D = phi(ep(k),Dp); c = D\y; D_eval = phi(ep(k),Dp_eval); err(k) = norm(D_eval*c - f(X_eval))/sqrt(M); end clf; semilogy(ep,err,'o-'); xlabel('\epsilon'); ylabel('error');

Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 1.370040e-19. Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 3.131817e-19. Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 3.574753e-19. Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 4.025069e-19. Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 1.113248e-20. Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 9.176172e-20. Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 2.530126e-19. Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 8.833138e-20. Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 1.490829e-19. Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 2.393086e-19. Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 3.052386e-19. Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 3.709531e-20. Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 2.976987e-19. Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 5.095278e-19. Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 1.794570e-19. Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 4.792528e-19. Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 1.101763e-19. Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 1.012590e-19. Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 2.308580e-20. Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 1.794831e-19. Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 2.542761e-19. Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 1.090377e-18. Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 6.881811e-19. Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 1.569937e-18. Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 1.167608e-19. Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 5.569164e-19. Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 1.849779e-18. Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 2.179062e-18. Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 1.821990e-17. Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 2.157355e-17. Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 6.916949e-17.