clear all

% Plot a comparison of first-order and second-order decays showing that 
% successive half lives are constant for first-order but grow for second
% order.  
%
% Executes properly on MATLAB version 9.4.0.813654 (R2018a).
% Executes mostly properly on OCTAVE version 4.2.1.
% Joshua C. Vaughan 4/16/2020

t = linspace(0,40,1000);
k = 0.2;

Aexp = exp(-k*t);
A2nd = 1./(1+k*t);

% create plot
figure(1); clf
%set(gcf,'position',[1233         200         591         437])
ax_lw = 2;
pl_lw = 2;
ax_fs = 24;
la_fs = 24;
fontname = 'Arial';

dx = 0.05; 
plot(t,Aexp,'b',t,A2nd,'r','linewidth',3)
hold on
xlabel('time (s)','fontsize',la_fs)
ylabel('[A({\itt})]','fontsize',la_fs)
set(gca,'fontsize',la_fs)
set(gca,'linewidth',ax_lw)
set(gca,'tickdir','out')
set(gcf,'color',[1 1 1])
set(gca,'ytick',[0 0.125 0.25 0.5 1])
set(gca,'yticklabel',{'0','1/8','1/4','1/2','1'})
set(gca,'fontname',fontname)
xlim([0 max(t)])

% Here is a crazy way to annotate a plot
an_fs = 18;
ypos = 0.65;
txt_color = [0 0 0] + 0.4;
hold on
plot([3.5 3.5]-dx,[0 0.5],'b','linewidth',1)
plot([7 7]-dx,[0 0.25],'b','linewidth',1)
plot([10.5 10.5]-dx,[0 0.125],'b','linewidth',1)
plot([5 5]-dx,[0.5 ypos],'r','linewidth',1)
plot([15 15]-dx,[0.25 ypos],'r','linewidth',1)
plot([35 35]-dx,[0.125 ypos],'r','linewidth',1)
plot([0 35]-dx,[0 0]+ypos,'r','linewidth',1)
dy = -0.040;
text(2.5,ypos+dy,'5 s','fontsize',an_fs,'horizontalalignment','center','fontweight','bold','color',txt_color)
text(10,ypos+dy,'10 s','fontsize',an_fs,'horizontalalignment','center','fontweight','bold','color',txt_color)
text(25,ypos+dy,'20 s','fontsize',an_fs,'horizontalalignment','center','fontweight','bold','color',txt_color)
ypos2 = 0.05;
text(3.5/2,ypos2,'3.5','fontsize',an_fs,'horizontalalignment','center','fontweight','bold','color',txt_color)
text(3.5/2+3.5,ypos2,'3.5','fontsize',an_fs,'horizontalalignment','center','fontweight','bold','color',txt_color)
text(3.5/2+7,ypos2,'3.5','fontsize',an_fs,'horizontalalignment','center','fontweight','bold','color',txt_color)
scatter(([3.5 7 10.5]-dx),[0.5 0.25 0.125],50,'ko','filled')
scatter(([5 15 35]-dx),[0.5 0.25 0.125],60,'ks','filled')
hold off

%h = legend('1^{st} order   [A({\itt})]=\it{e}^{-\itkt}','2^{nd} order[A({\itt})]=1/(1+{\itkt})') % was too buzy
h = legend('1^{st} order','2^{nd} order');
set(h,'box','off')
set(h,'fontsize',20)
set(h,'position',[0.4  0.7169 0.6024 0.1979]);
set(gca,'LooseInset',get(gca,'TightInset'));
