%% Demonstrate rates of convergence
% In this demo, we'll see linear, superlinear, quadratic, cubic, and
% arithmetically convergence to zero.


%% Setup the plot
clf;
cla;
hold on;

k=(1:60)';
xlim([0,60]);
ylim([1e-8,1]);

%% Start with linear
seq = 0.85.^k
semilogy(k, seq, 'k-', 'LineWidth', 2);
text(max(k), seq(end), 'Linear', 'FontSize', 20);

% Fix small bug in matlab
set(gca,'YScale','log');

%% Arithmetic
semilogy(k, 1./k, ':', 'Color', [0,0.8,0], 'LineWidth', 2);

seq = 1./(k.^2)
semilogy(k, seq, ':', 'Color', [0,0.8,0], 'LineWidth', 2);
text(max(k), seq(end), 'Arithmetic', 'FontSize', 20);

%% Superlinear
seq = (2*k).^(-0.05*k)
semilogy(k, seq, '-.', 'Color', [0.8,0,0], 'LineWidth', 2);
text(max(k), seq(end), 'Superlinear', 'FontSize', 20);

%% Quadratic
seq = (0.99).^(2.^k)
semilogy(k, seq, '--', 'Color', 'm', 'LineWidth', 2);
text(12, 5e-8, 'Quadratic', 'FontSize', 20);

%% Cubic
seq = (0.99).^(3.^k)
semilogy(k, seq, '--', 'Color', 'y', 'LineWidth', 2);
text(5, 5e-8, 'Cubic', 'FontSize', 20, 'HorizontalAlignment','right');
