% Examples of interpolation


% Sech
x1 = [-4.5:0.1:4];
y1 = sech(x1);
x2 = [-4.25:1:4];
y2 = sech(x2);
figure(1);
plot_interp(x1,y1,x2,y2,'y = sech(x) -- which scheme captures the peak best?');
legend('location','northwest');

% Sign
x1 = [-1.5:0.01:1.5];
y1 = sign(x1);
x2 = [-1.4:0.4:1.4];
y2 = sign(x2);
figure(2);
plot_interp(x1,y1,x2,y2,'y = sign(x) -- a discontinuous, monotonic function.');
legend('location','northwest');

% Two slightly misaligned data sets
x1 = [0 : 0.01 : 4];
y1 = exp(-x1);
x2a = [0 : 0.5 : 2];
x2b = [2.1 : 0.5 : 4];
y2a = exp(-x2a);
y2b = exp(-x2b);
x2b = x2b - 0.09; % Data offset error
% x2b -= 0.09; % Shorter way to do it in Octave! :-)
x2 = [x2a, x2b];
y2 = [y2a, y2b];
figure(3);
plot_interp(x1,y1,x2,y2,'y = exp(-x), but with misaligned data.');

% 1/(1+|x|)
x1 = [-4:0.01:4];
y1 = 1./(1+abs(x1));
x2 = [-3:.5:3];
y2 = 1./(1+abs(x2));
figure(4);
plot_interp(x1,y1,x2,y2,'y = 1/(1+|x|) -- discontinuous first derivative.');
legend('location','northwest');

% Piecewise Gaussians, factor of 3 change in 2nd deriv at origin.
x1a = [-4:0.1:0];
y1a = exp(-x1a.^2);
x1b = [0.1:0.1:4];
y1b = exp(-x1b.^2/9);
x1 = [x1a,x1b];
y1 = [y1a,y1b];
x2a = [-4:0.5:0];
y2a = exp(-x2a.^2);
x2b = [0.5:0.5:4];
y2b = exp(-x2b.^2/9);
x2 = [x2a,x2b];
y2 = [y2a,y2b];
figure(5);
plot_interp(x1,y1,x2,y2,'Piecewise Gaussians, factor of 3 change in 2nd deriv at origin.');
legend('location','northwest');

% ( (1-|x|)^2 - 1 ) * sign(x)
x1 = [-2.5:0.01:2.5];
y1 = ( (1-abs(x1)).^2 - 1 ) .* sign(x1);
x2 = [-2:2/3:2];
y2 = ( (1-abs(x2)).^2 - 1 ) .* sign(x2);
figure(6);
plot_interp(x1,y1,x2,y2,'y = ( (1-|x|)^2 - 1 ) * sign(x) -- two parabolas.');
legend('location','northeast');

