clear all

% Plot the concentrations of A, B, C for the bimolecular addition reaction 
% A+B->C which is first-order with respect to both A and B.  
%
% Executes properly on MATLAB version 9.4.0.813654 (R2018a).
% Executes mostly properly on OCTAVE version 4.2.1.
% Joshua C. Vaughan 5/16/2020

k = 0.4;  % 1/(M*s)
Ao = 0.15;
Bo = 0.25;

n = 2^12;
t = linspace(0,100,n);

g = exp( k*t*(Bo-Ao) );
x = Ao*( 1 - g )./( Ao/Bo - g );

t_half = log(2-Ao/Bo)/(k*(Bo-Ao));

C = x;
A = Ao-x;
B = Bo-x;

% create plot
figure(1); clf
ax_lw = 2;
pl_lw = 2;
ax_fs = 24;
la_fs = 24;
lg_fs = 24;
fontname = 'Arial';

plot(t,A*1000,'k',t,B*1000,'r',t,C*1000,'b','linewidth',pl_lw)
xlabel('time (s)')
ylabel('concentration (mM)')
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)])
h = legend('[A({\itt})]','[B({\itt})]','[C({\itt})]');
set(h,'box','off')
set(h,'fontsize',lg_fs)
set(gca,'LooseInset',get(gca,'TightInset'));
